You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[4.2.0] bug: ion-datetime does not displays the correct date if set programatically (e.g. using reactive forms or by [ngModel] prop) #17977
I give a date in format 'YYYY-MM-DD' and ionic displays the date of the previous day.
I pick a date and the output is an ISO string with the date converted to UTC from the user's timezone.
These are unexpected to me because I didn't specify a timezone for the date I passed to the ion-datetime. I expect the component to display the date as I passed it and to return the picked date in the same format I first passed (YYYY-MM-DD) without timezone changes from what is displayed.
Also, if I do pass a date with timezone I would expect ion-datetime to do these conversions for me.
I don't know if this behavior would fit better as an option for the component to use either no timezone or user timezone.
I made a repo that reproduces this bug. It has a text input that passes its string value to an ion-datetime and another text input that shows the value output by the ion-datetime.
You need to set your computer's timezone to a negative timezone, the screenshot below was taken with timezone GMT-5.
Thanks for additional info. I can confirm that this is a bug.
It's technically correct as the JS Date implementation assumes 2019-03-20 00:00.00 and applies a timezone offset (in this case GMT-5) which would bring you to 2019-03-19 19:00.00. For what we are trying to provide with ion-datetime, this is not desired functionality.
I will work on getting a fix in for this. As an (odd) workaround, adding a single space after your input appears to fix the issue.
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.
Activity
liamdebeasi commentedon Apr 5, 2019
Hi there,
Thanks for the issue. I am unable to reproduce this:
What timezone are you in? I can try changing my clock's timezone to yours and see if that makes a difference.
Thanks!
davl3232 commentedon Apr 8, 2019
Hi Liam,
I'm facing this same issue.
Two unexpected things happen:
These are unexpected to me because I didn't specify a timezone for the date I passed to the ion-datetime. I expect the component to display the date as I passed it and to return the picked date in the same format I first passed (YYYY-MM-DD) without timezone changes from what is displayed.
Also, if I do pass a date with timezone I would expect ion-datetime to do these conversions for me.
I don't know if this behavior would fit better as an option for the component to use either no timezone or user timezone.
I made a repo that reproduces this bug. It has a text input that passes its string value to an ion-datetime and another text input that shows the value output by the ion-datetime.
You need to set your computer's timezone to a negative timezone, the screenshot below was taken with timezone GMT-5.
https://github.com/davl3232/prueba-fechas
Thank you.
liamdebeasi commentedon Apr 11, 2019
Hi there,
Thanks for additional info. I can confirm that this is a bug.
It's technically correct as the JS Date implementation assumes
2019-03-20 00:00.00and applies a timezone offset (in this case GMT-5) which would bring you to2019-03-19 19:00.00. For what we are trying to provide withion-datetime, this is not desired functionality.I will work on getting a fix in for this. As an (odd) workaround, adding a single space after your input appears to fix the issue.
Thanks!
liamdebeasi commentedon Apr 16, 2019
Hi there,
This issue has been fixed and will be in the next release of Ionic.
Thanks!
davl3232 commentedon Apr 24, 2019
Hi, it's working on 4.3.0. Thank you!
ionitron-bot commentedon May 24, 2019
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.