New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date.month crash with dates in the distant future #690

Closed
MrMovl opened this Issue Aug 11, 2016 · 3 comments

Comments

Projects
None yet
4 participants
@MrMovl

MrMovl commented Aug 11, 2016

If you manage to get an invalid date like Date.fromTime 10000000000000000, everything works until you try something like notADate |> Date.month |> toString |> Html.text. Then you get the runtime Error Uncaught TypeError: Cannot read property 'substring' of undefined It's the same for Date.dayOfWeek.

This seems unlikely, but you can reach that pretty quick when extrapolating Dates. Not sure if this can be fixed with the Date.month function. Maybe the problem could be solved if Date.fromTime would behave like Date.fromString and yield a Result or a Maybe.

Can be reproduced with the following on http://elm-lang.org/examples/hello-html

import Html
import Date

main =
let
notAMonth = Date.fromTime 10000000000000000 |> Date.month
in
notAMonth |> toString |> Html.text

@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

process-bot Aug 11, 2016

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

process-bot commented Aug 11, 2016

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

@lukewestby lukewestby added the bug label Sep 12, 2016

@evancz evancz changed the title from Date.month causes problems and potential runtime errors with invalid dates to Date.month crash with dates in the distant future Sep 23, 2016

@kuzux

This comment has been minimized.

Show comment
Hide comment
@kuzux

kuzux Dec 27, 2016

Just managed to reproduce the crash using Date.fromTime 10000000000000000 |> Date.month in repl

edit: Looking more into it, it seems to be caused by V8 JS engine returning a NaN citing invalid range error in new Date(). When we try to do anything with it, it just crashes. Adding an isNaN check on Date.fromTime should suffice.

kuzux commented Dec 27, 2016

Just managed to reproduce the crash using Date.fromTime 10000000000000000 |> Date.month in repl

edit: Looking more into it, it seems to be caused by V8 JS engine returning a NaN citing invalid range error in new Date(). When we try to do anything with it, it just crashes. Adding an isNaN check on Date.fromTime should suffice.

@lukewestby lukewestby referenced this issue Jan 20, 2017

Closed

Date #816

2 of 7 tasks complete
@lukewestby

This comment has been minimized.

Show comment
Hide comment
@lukewestby

lukewestby Jan 20, 2017

Member

Tracking in #816

Member

lukewestby commented Jan 20, 2017

Tracking in #816

@lukewestby lukewestby closed this Jan 20, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment