ionic2 - unable to update date in datetimepicker
When I was changing just the day for example in the datepicker nothing changed and the console logged
Error parsing date: "[object Object]". Please provide a valid ISO 8601 datetime format: https://www.w3.org/TR/NOTE-datetime
As I looked in the code I found that there are missing conditions in the updateDate function in datetime-utils.js
else if ((isPresent(newData.year) || isPresent(newData.hour))) {
if (isPresent(newData.ampm) && isPresent(newData.hour)) {
if (newData.ampm.value === 'pm') {
newData.hour.value = (newData.hour.value === 12 ? 12 : newData.hour.value + 12);
}
else {
newData.hour.value = (newData.hour.value === 12 ? 0 : newData.hour.value);
}
}
for (var k in newData) {
existingData[k] = newData[k].value;
}
return;
}
console.warn(`Error parsing date: "${newData}". Please provide a valid ISO 8601 datetime format: https://www.w3.org/TR/NOTE-datetime`);
As you see the date is only changed if either the year or the hour has changed. I guess that was forgotten?
I could do an PR and add month, day, minute, and second if needed. Used this fix locally for a fast workaround.
@tobika Please go ahead with the PR! Can you provide a test that fails without your fix? I am not sure what bug you are trying to fix.
Thanks!
Just to explain better, the bug appears in two configurations on your example page http://ionicframework.com/docs/v2/demos/src/datetime/?production=true&ionicplatform=mdl
When you try the "Chrome" example on this page you can only change month and day (same in my app), when the updateDate function runs it checks if either the year or hour parameter exists, if not (like in this case) it logs a warning
Same for the "alert" example where you only choose the minutes and nothing else.
I would say that we should at least check month, day and minutes. Will add the tests(there are no tests yet for this function) that fail and then make a fix/
@tobika did you solve this issue? i have the issue too
@adirzoari @manucorporat yes, there is a PR waiting with the correction #8387
@tobika sorry i'm new in github,where is it? i check in the #8387 and i don't see the answer for that.. do you use also ionic2?
@adirzoari if you click on the link I just posted you can switch to Files Changed to see the new code that has been added to fix the problem
As a workaround you can just go into the file /node_modules/ionic-angular/util/datetime-utils.js
and change the in the updateDate function the following code:
- } else if ((isPresent(newData.year) || isPresent(newData.hour))) {
+ } else if ((isPresent(newData.year) || isPresent(newData.hour) || isPresent(newData.month) || isPresent(newData.day) || isPresent(newData.minute) || isPresent(newData.second))) {
Remove the line with the - and add the line with +
@tobika you use ionic 2 also?
@adirzoari yes
Merged!
@tobika have u solve this , i have a same problem
@manikandan07081995 could you give more info which error you have? this PR was merged and normally everything should work as this bug was fixed
@tobika issue closed.
Hi, @tobika. I have same issue, im getting a date with ngModel, but when i set this date (with ion-datetime) this error appear:
datetime-util.js:229 Error parsing date: "Wed Feb 28 2018 09:56:12 GMT-0300 (Hora oficial do Brasil)". Please provide a valid ISO 8601 datetime format: https://www.w3.org/TR/NOTE-datetime.
Has this problem been resolved yet?
Thanks in advance
Hi @edisonmatoso
this is not a problem with the datetimepicker, you have to give the correct date data to the ngmodel.
The error message gives you the details becaus your format you are trying to pass is not valid Wed Feb 28 2018 09:56:12 GMT-0300 (Hora oficial do Brasil).
It should be the ISO 8601 format: 2011-10-05T14:48:00.000Z
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.