Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upDate.fromString should not rely on new Date(...) #632
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
halfzebra
May 31, 2016
Contributor
Date constructor in JavaScript offers consistent parsing behavior only for ISO 8601 formatted date strings.
You have happened to use an invalid ISO 8601 date string, which leads to that error.
Maybe it would make sense to add some validation mechanism to Native.Date.fromString to ensure, that Date constructor will only get a valid ISO 8601 formatted date.
E.g. JavaScript implementation of http://www.pelagodesign.com/blog/2009/05/20/iso-8601-date-validation-that-doesnt-suck/
|
You have happened to use an invalid ISO 8601 date string, which leads to that error. Maybe it would make sense to add some validation mechanism to E.g. JavaScript implementation of http://www.pelagodesign.com/blog/2009/05/20/iso-8601-date-validation-that-doesnt-suck/ |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Zimmi48
May 31, 2016
@halfzebra Thanks for the feedback.
I get what you mean and yes, I think it would make sense to add a validation mechanism, or even better, re-implement the function in pure Elm: a well-behaved language such as Elm shouldn't rely on inconsistent implementations in JS. If a function behaves in some way in the repl, it should behave in the same way in the browser.
Zimmi48
commented
May 31, 2016
|
@halfzebra Thanks for the feedback. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Zimmi48
May 31, 2016
To confirm that this is a problem imported from JS: on Chromium, the same program displays Error
Zimmi48
commented
May 31, 2016
|
To confirm that this is a problem imported from JS: on Chromium, the same program displays |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
avh4
Jun 1, 2016
Member
If someone can implement validation or pure-elm parsing and merge it to rluiten/elm-date-extra or another published package, that would be a good start.
|
If someone can implement validation or pure-elm parsing and merge it to rluiten/elm-date-extra or another published package, that would be a good start. |
evancz
changed the title from
Problem with date parsing
to
new Date(...) works different in different browsers
Jun 25, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mariosangiorgio
Aug 27, 2016
Contributor
Hello, is there any update on this issue? I just got confused by the formats used by Date.fromString and opened #701 (sorry for the duplicate)
|
Hello, is there any update on this issue? I just got confused by the formats used by |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
halfzebra
Aug 29, 2016
Contributor
Date.Extra.fromIsoString is capable of parsing ISO 8601 date strings, without causing run-time errors.
I do agree with everything, from #701, Date.fromString should have some extra validation.
|
Date.Extra.fromIsoString is capable of parsing ISO 8601 date strings, without causing run-time errors. I do agree with everything, from #701, |
evancz
referenced this issue
Aug 29, 2016
Closed
Date.fromString calls strongly discouraged Javascript code #701
evancz
changed the title from
new Date(...) works different in different browsers
to
Date.fromString should not rely on new Date(...)
Sep 23, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
daniellandau
Oct 6, 2016
I just ran into a problem with this in production. My situation is that I rely on Date.fromString to fail on invalid input so that Json.oneOf tries the next decoder in the list. In Firefox this works perfectly, but Chrome/Chromium happily give a nonsensical but valid date with for example new Date("3")
daniellandau
commented
Oct 6, 2016
|
I just ran into a problem with this in production. My situation is that I rely on |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
halfzebra
Oct 6, 2016
Contributor
@daniellandau for now you can use Json.Decode.andThen to parse a string firs and then do Date.Extra.fromIsoString to parse it properly.
|
@daniellandau for now you can use Json.Decode.andThen to parse a string firs and then do Date.Extra.fromIsoString to parse it properly. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Tracking in #816 |
Zimmi48 commentedMay 30, 2016
•
edited
Edited 1 time
-
Zimmi48
edited May 31, 2016 (most recent)
Hello,
The following SSCCE shows an unexpected result
2011when we should instead displayError:(tried in elm-lang.org/try in Firefox)
This problem does not arise in elm repl: