Invalid date in safari and IOS (ionic framework)

0

I have the following Json with dates:

nuevo=[
    { "rr":"4-1-2016" }, { "rr":"4-2-2016" }, { "rr":"4-3-2016" },
    { "rr":"4-4-2016" }, { "rr":"4-5-2016" }, { "rr":"4-6-2016" },
    { "rr":"4-7-2016" }, { "rr":"4-8-2016" }, { "rr":"4-9-2016" },
    { "rr":"4-10-2016" }, { "rr":"4-11-2016" }, { "rr":"4-12-2016" },
    { "rr":"4-13-2016" }, { "rr":"4-14-2016" }, { "rr":"4-15-2016" },
    { "rr":"4-16-2016" }, { "rr":"4-17-2016" }, { "rr":"4-18-2016" },
    { "rr":"4-19-2016" }, { "rr":"4-20-2016" }, { "rr":"4-21-2016" },
    { "rr":"4-22-2016" }, { "rr":"4-23-2016" }, { "rr":"4-24-2016" },
    { "rr":"4-25-2016" }, { "rr":"4-26-2016" }, { "rr":"4-27-2016" },
    { "rr":"4-28-2016" }, { "rr":"4-29-2016" }, {"rr":"4-30-2016" },
    { "rr":"5-1-2016" },{ "rr":"5-2-2016" },{ "rr":"5-3-2016" },
    { "rr":"5-4-2016" },{ "rr":"5-5-2016"} ,{ "rr":"5-6-2016" },
    { "rr":"5-7-2016" },{ "rr":"5-8-2016" },{ "rr":"5-9-2016" },
    { "rr":"5-10-2016" },{ "rr":"5-11-2016" },{ "rr":"5-12-2016" },
    { "rr":"5-13-2016" },{ "rr":"5-14-2016" },{ "rr":"5-15-2016" },
    { "rr":"5-16-2016" },{ "rr":"5-17-2016" },{ "rr":"5-18-2016" },
    { "rr":"5-19-2016" },{ "rr":"5-20-2016" },{ "rr":"5-21-2016" },
    { "rr":"5-22-2016" },{ "rr":"5-23-2016" },{ "rr":"5-...16" },
    { "rr":"6-14-2016" },{ "rr":"6-15-2016" },{ "rr":"6-16-2016" },
    { "rr":"6-17-2016" },{ "rr":"6-18-2016" },{ "rr":"6-19-2016" },
    { "rr":"6-20-2016" },{ "rr":"6-21-2016" },{ "rr":"6-22-2016" },
    { "rr":"6-23-2016" },{ "rr":"6-24-2016" },{ "rr":"6-25-2016" },
    { "rr":"6-26-2016" },{ "rr":"6-27-2016" },{ "rr":"6-28-2016" },
    { "rr":"6-29-2016" },{ "rr":"6-30-2016" },{ "rr":"7-1-2016" },
    { "rr":"7-2-2016" },{ "rr":"7-3-2016" },{ "rr":"7-4-2016" },
    { "rr":"7-5-2016" },{ "rr":"7-6-2016" },{ "rr":"7-7-2016" },
    { "rr":"7-8-2016" },{ "rr":"7-9-2016" },{ "rr":"7-10-2016" },
    { "rr":"7-11-2016" },{ "rr":"7-12-2016" },{ "rr":"7-13-2016" },
    { "rr":"7-14-2016" },{ "rr":"7-15-2016" },{ "rr":"7-16-2016" },
    { "rr":"7-17-2016" },{ "rr":"7-18-2016" },{ "rr":"7-19-2016" },
    { "rr":"7-20-2016" },{ "rr":"7-21-2016" },{ "rr":"7-22-2016" },
    { "rr":"7-23-2016" },{ "rr":"7-24-2016" },{ "rr":"7-25-2016" },
    { "rr":"7-26-2016" },{ "rr":"7-27-2016" },{ "rr":"7-28-2016" },
    { "rr":"7-29-2016" },{ "rr":"7-30-2016" },{ "rr":"7-31-2016" },
    { "rr":"8-1-2016" },{ "rr":"8-2-2016" },{ "rr":"8-3-2016" },
    { "rr":"8-4-2016" },{ "rr":"8-5-2016" }
];

Which I turn into momentarily every item; the result should be like this: April-Friday-2016, April-Saturday-2016, April-Sunday-2016, etc ... In browsers such as Chrome and Android OS the result is correct but by showing the result in an alert in safari or IOS results in invalid date

for(var p = 0; p < nuevo.length; p++){
    alert(moment(nuevo[p].rr).format('MMMM-dddd-YYYY'));
}

Why this error occurs, what should I do?

I also have the following error in console:

  

Deprecation warning: moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release. Please refer to link for more info.   Arguments: [object Object]

    
asked by Dimoreno 23.06.2016 в 23:30
source

1 answer

0

What is happening here is that your dates are not in the format of standard dates ISO 8601 . Moment.js uses new Date () internally to create the dates and when you pass a non-standard format depends mainly on the browser interpret the date and therefore some works for you and others do not.

The solution for this is to give it as format of entries to your dates the accepted standard that is something like

 YYYY-MM-DDTHH:mm:ss.sssZ

You are using

M-D-YYYY

Store your dates in the standard format or transform them manually before parsing them. I always recommend the first variant.

You can read a little more about the standard in the spec of javascript and in the following links

link

link

    
answered by 24.06.2016 / 16:28
source