Skip to content
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

should parse fail when out of range? #47

Open
rnons opened this issue Jun 1, 2018 · 2 comments
Open

should parse fail when out of range? #47

rnons opened this issue Jun 1, 2018 · 2 comments

Comments

@rnons
Copy link

rnons commented Jun 1, 2018

Is this behavior expected?

var d3TimeFormat = require("d3-time-format")

d3TimeFormat.timeParse('%m/%d/%Y')('26/1/2017') // Fri Feb 01 2019 00:00:00 GMT+0900 (JST)
d3TimeFormat.timeParse('%d/%m/%Y')('26/1/2017') // Thu Jan 26 2017 00:00:00 GMT+0900 (JST)

I read from README %m - month as a decimal number [01,12]., so I would like d3TimeFormat.timeParse('%m/%d/%Y')('26/1/2017') to return null, is that possible?

Thank you.

@ggmod
Copy link

ggmod commented Jul 18, 2018

I encountered the same issue. Looking at the d3 code it seems that actually it's the JavaScript Date constructor that is responsible for this behavior, and d3 just uses the Date constructor to create the final result.

I can't imagine how this behavior could ever be useful, and it certainly caused problems for me: in my use case when the user supplied data changed its format from month-day-year to day-month-year, my app produced nonsense results instead of throwing an error. I also wanted to use d3 for automatically detecting the format by trying out different patterns, but it can't distinguish between month-day-year and day-month-year because of this issue.

It would be great if d3 could validate if some fields are out of range, maybe using a flag for "extra strict" behavior.

@mbostock
Copy link
Member

I think this would be difficult to implement, and I don’t have any current plans to support this feature, but it might make a good contribution if someone is interested.

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

No branches or pull requests

3 participants