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

Parsing Negative Unix Values Fail #87

Open
iltimasd opened this issue Jul 8, 2020 · 1 comment
Open

Parsing Negative Unix Values Fail #87

iltimasd opened this issue Jul 8, 2020 · 1 comment

Comments

@iltimasd
Copy link

iltimasd commented Jul 8, 2020

Any negative unix value is failed to be correctly parsed

> var parseUnix = d3.timeParse("%Q")

> parseUnix(978325200000).toString()
"Mon Jan 01 2001 00:00:00 GMT-0500 (Eastern Standard Time)"

> parseUnix(0).toString()
"Wed Dec 31 1969 19:00:00 GMT-0500 (Eastern Standard Time)"

> parseUnix(-1)
null

Note that formatting dates prior to epoch, returns negative values

> var formatUnix = d3.timeFormat("%Q");

> formatUnix(new Date(-1))
-1

> var parseUnix = d3.timeParse("%Q")

> parseUnix(formatUnix(new Date(-1)))
null

As you may have noticed that the native JS Date constructor is able to parse negative Unix time, so not a huge problem for basic tasks, but support for parsing negative values may be needed in more complex tasks.

@mbostock
Copy link
Member

mbostock commented Jul 8, 2020

Yep, this parser uses the generic numberRe, which doesn’t allow a leading negative sign (since that doesn’t match sense for most other fields). We should consider adding it.

numberRe = /^\s*\d+/, // note: ignores next directive

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

2 participants