Skip to content

Unexpected Date.parse behaviour #963

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

Closed
willholley opened this issue Mar 10, 2025 · 2 comments
Closed

Unexpected Date.parse behaviour #963

willholley opened this issue Mar 10, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@willholley
Copy link

QuickJS appears to unexpectedly parse date strings containing epoch seconds, unlike other major JS engines.

For example, attempting to parse string containing "1065873600" (Saturday, October 11, 2003 12:00:00 PM):

qjs > Date.parse("1065873600")
946684800000

946684800000 represents Saturday, January 1, 2000 12:00:00 AM, which is incorrect.

In other JavaScript engines (e.g. SpiderMonkey, V8), Date.parse("1065873600") returns NaN, so I expected similar behavior from qjs.

I appreciate that the specification of Date.parse allows for implementation-specific fallbacks - I just couldn't find a description of the intended behavior so better understand whether this is intended behavior or a bug.

@bnoordhuis bnoordhuis added the enhancement New feature or request label Mar 10, 2025
@bnoordhuis
Copy link
Contributor

I don't know if I'd call it a bug, more like GIGO (Garbage In, Garbage out.) Pull request welcome, I'd say.

What happens is that js_date_parse_otherstring parses the first 9 digits as a timestamp, then sees the final "0" and interprets that as a short-version year, superseding the timestamp, hence January 1, 2000.

@nickva
Copy link
Contributor

nickva commented Mar 11, 2025

I tried to fix it upstream and since it's the same change made pr here as well #967

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants