Live data from Hacker News

Why are 2025/05/28 and 2025-05-28 different days in JavaScript?

brandondong.github.io

61–70 of 167 posts

Re: Why are 2025/05/28 and 2025-05-28 different days in JavaScript?

#61
post #33

Earlier quoted context omitted.

Kind of funny that you think the open web still exists. I mean, even Microsoft gave up and just went with Chromium, and they got the definition of almost infinite resources at their disposal. Effectively if your website doesn't run in Chrome and Safari, it won't be seen by 99% of the market.

> even Microsoft gave up Ah yes, Microsoft, the defenders of the free world.

Embrace

Extend

Enhance the world's beauty

Re: Why are 2025/05/28 and 2025-05-28 different days in JavaScript?

#62
post #48
post #16

Undocumented Undefined Behaviour, anyone?

It's documented undefined behavior, really. Implementations are allowed to accept other input than ISO strings and interpret them how they like. The real "bug" in the example is 2025/05/28 being May 28th because the implementation ignores timezones for that format. The issue with `Date` is that it is based on the original `java.util.Date` class and inherits all of its problems: https://docs.oracle.com/en/java/javase/…

how about postgres style timestamp and timestamptz

unless a timezone/offset is given, its considered plain date/time, not an epoch.

Re: Why are 2025/05/28 and 2025-05-28 different days in JavaScript?

#63
post #52

Earlier quoted context omitted.

Because Americans use slashes commonly in Y/D/M

Wait, I thought Americans use M/D/Y not Y/D/M?

This is correct, the most common short-hand format in America is MM/DD/YYYY (possibly two digits in the last group). Dates like 05/28/2025 and 28/05/2025 are unambiguous enough to deal with order differences, dates like 06/03/2025 are not.

Year first and dashes is pretty much exclusively YYYY-MM-DD, no ambiguity; 2025-03-06 cannot be interpreted in any manner other than "the sixth day of the third month of the year 2025"

Re: Why are 2025/05/28 and 2025-05-28 different days in JavaScript?

#64
post #52

Earlier quoted context omitted.

Because Americans use slashes commonly in Y/D/M

Wait, I thought Americans use M/D/Y not Y/D/M?

We do, almost exclusively.

We'll use Y/M/D for systems or ordering, sometimes.

I can't recall having ever seen Y/D/M used in any notable sense.

Re: Why are 2025/05/28 and 2025-05-28 different days in JavaScript?

#65

Earlier quoted context omitted.

How is slashes ambiguous if you use YYYY and in YMD order?

Because Americans use slashes commonly in Y/D/M

No we don’t. I’m American and I’ve never seen this format.

Re: Why are 2025/05/28 and 2025-05-28 different days in JavaScript?

#66

I recently spent 2 hours on finding the bug, precisely because JS can't comprehend dates/times without a Unix timestamp underneath. I'd take a date from Postgres as e.x. "2025-05-24" and the first time somewhere deep in the package I was using, when JS encountered that, it needed to add a time (midnight, that's sane) and timezone (local time :) ). I was trying to use UTC everywhere and since the read dates had midnig…

> it needed to add a time (midnight, that's sane)

Is it sane? Is midnight at the start of a day, or the end of it? I'd think noon would be less ambiguous, and significantly less prone to these timezone issues (although this may not be a benefit).

Re: Why are 2025/05/28 and 2025-05-28 different days in JavaScript?

#68
post #30

Earlier quoted context omitted.

RFC3339. ISO 8601 allows for 2 or 6 digit years. Truncating to 2 is just incorrect, and 6 digits is absurd. And you can read the RFC without paying ISO - and you can discuss the RFC with people who have also read it instead of relying on people using the Wikipedia page to interpret and explain ISO 8601. I have a scheduling service at work and I keep getting requests for implementing ISO 8601 timestamps but I ignore t…

There's this handy venn diagram that I've seen floating around for a long time. Just found a random link to it with an image search: https://gyazo.com/d8517f72e24c38f055e17182842b991c/max_size/... ISO 8601 does have some strange formats...

> ISO 8601 does have some strange formats...

Not that I’ve ever really had cause to use it in anger, but I like the idea of ISO week dates.

Effectively, the ISO weak year (often differs from the calendar year in the last week of December / first week of January), ISO week number and day of week form a leap week calendar - instead of having 365 days in a common year and 366 in a leap year, it has 364 days in a common year and 371 in a leap week year, with leap weeks (obviously) being less frequent than leap days.

The Sym454 calendar [0] takes this idea further to create a perpetual calendar, with 12 months of 4 or 5 weeks; in leap years the 12th month is 5 weeks instead of 4 weeks long. However, the leap week rule proposed by Sym454 is different from that proposed by ISO 8601; the author of Sym454 argues his proposed rule has theoretical advantages (simple calculation and more uniform distribution of leap weeks). That said, there is a variant of Sym454 which uses the ISO 8601 leap week rule.

[0] https://kalendis.free.nf/symmetry.htm?i=1

Re: Why are 2025/05/28 and 2025-05-28 different days in JavaScript?

#69
After carefully reading the timeline, I think the most surprising part is that when Chrome switched again to defaulting to local time for date-only forms in 2015 (together with date-time form), someone complained it was a "breaking change", despite the fact that it was simply following the spec, and it even went so far that it eventually caused the spec itself to change, and now we’re stuck with the Frankenstein mess we have today.

By that, I don't mean to dismiss the importance of backward compatibility, but this case is particularly funny because:

1. It had already been changed multiple times, each a breaking change, so it’s not like this form of compatibility was ever seriously respected;

2. Having it behave differently from other "legacy forms," like the slash-separated version, is itself arguably a break in backward compatibility;

3. As noted in the article, it never worked the same between Chrome and Firefox (at this point) anyway, so it’s doubtful how impactful this "breaking change" really was, considering you already had to write shim code either way.

Re: Why are 2025/05/28 and 2025-05-28 different days in JavaScript?

#70

Earlier quoted context omitted.

How is slashes ambiguous if you use YYYY and in YMD order?

Because Americans use slashes commonly in Y/D/M

YDM is very rare; according to Wikipedia, only found in Kazakhstan, Latvia, Nepal, and Turkmenistan, and even in those countries it commonly coexists with other formats.

I believe internationally that YMD and DMY are the two most common formats (and also the most logical), and the (much less logical) MDY comes third… YDM is a very distant fourth. MYD, DYM are theoretically possible but doubt anybody uses them

Actually, although MDY is by far most common in the US, I’ve seen US federal government forms that use DMY instead (although I imagine that’s rare, I’m sure you’ll find DMY US govt forms are greatly outnumbered by MDY ones)

Post reply on HN