Closed marechalsamuel closed 6 years ago
After searching and testing, it seems parsing gets an error on timezone whenever it's not the default timezone or the one that is set. Getting this error message : Pattern value mismatch
Here is the test :
https://plnkr.co/edit/SBZDc5CaaFLsJ9eKzuAE?p=preview
I'm not sure what you are going to achieve.
If you want to use 1976-11-14T07:05:58+01:00
as default value, you can convert the date string into a date object: https://plnkr.co/edit/9YRgQClGD9gpVQSeLlzT?p=preview
If you want to create a datetime input with specific timezone (+0100), currently you can't. There is only a datetime-utc
flag to use +0000 as timezone.
And here is why you got the date of the day:
new Date()
.Converting my string into a date object will do it. I guess parsing timezone is work in progress, maybe meanwhile it would be convenient to add a note in the readme about ZZ on this point ? Thank you anyway for your reactivity and also for you work !
There were some discussions to make timezone "editable", but this feature is rarely used. Most of the time we only save the date into database without timezone information, and display the date to users in their local timezone. If timezone information is needed, we use another field to record it.
However, it would be good if we can make timezone "parsable", which should work like this:
datestr = "1976-11-14T07:05:58+01:00";
parser = datetime("yyyy-MM-ddTHH:mm:ssZZ");
date = parser.parse(datestr, true).getDate(); // a flag allowing the parser to switch the timezone automatically
date.getTime() == new Date(datestr).getTime(); // true
parser.inTimezone("+01:00"); // true
For information, we found a neat solution to handle the issue making a directive with $parsers and $formatters having a priority of 101 (superior to this library)
https://plnkr.co/edit/g2tPcae2mfdp3PHo9HZ1?p=preview
I guess this could be directly done inside the library.
You will get the date in local timezone with that code, also the colon :
is missing.
If timezone doesn't matter, I would do something like this: https://plnkr.co/edit/MRAoBt8Cam6YbmlvHgkb?p=preview
Now you can use datetime-zone
to specify a custom timezone.
I can't get to parse some w3c formatted dates properly, If the timezone is +01:00, it seems to go wrong and I get the date of the day. Here is an example : https://plnkr.co/edit/g2tPcae2mfdp3PHo9HZ1?p=preview