Live data from Hacker News

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

brandondong.github.io

41–50 of 167 posts

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

#41
post #7

Hang on, slashes and year-month-day? https://en.wikipedia.org/wiki/ISO_8601 Handed down by the ISO, The Great Compromise allows YYYY-MM-DD (or YYYYMMDD if you're in a hurry) but the version with slashes I'd find ambiguous and upsetting, especially early in the month. The standard is good, and you can get it from `date -I`. Hell mend anyone who messes with the delimiters or writes the year in octal or any other heresy…

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

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

#42
post #8
post #6

How did they manage to build the entire modern Web on a language without a standard library?

The world where JavaScript has a robust standard library is one where there is only one browser vendor who gets to call all the shots regarding what the web looks like. That is not a better world.

I want that world.

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

#43
post #7

Hang on, slashes and year-month-day? https://en.wikipedia.org/wiki/ISO_8601 Handed down by the ISO, The Great Compromise allows YYYY-MM-DD (or YYYYMMDD if you're in a hurry) but the version with slashes I'd find ambiguous and upsetting, especially early in the month. The standard is good, and you can get it from `date -I`. Hell mend anyone who messes with the delimiters or writes the year in octal or any other heresy…

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

Because Americans use slashes commonly in Y/D/M

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

#44
post #9

Earlier quoted context omitted.

There's even worse language language for this. It's absolutely essential for an modern e-commerce, but has no official standard or spec, many thousands of libraries but they're mostly poorly maintained and geoblocked. The language itself is just a hodge podge of other languages that were popular in the past, and as a result it's worse than Perl for having too many ways to do any single thing. The major dialects may b…

PHP?

Rather than spoil this tremendous piece of humour, I'll just give a rot13-encrypted version of the answer: Ratyvfu

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

#45
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 midnight of UTC+2 as the time, they were all a day behind in UTC.

Special shoutouts to the author of node-postgres saying the PG's date type is better not used for dates in this case.[1] I love programming.

[1] https://node-postgres.com/features/types#date--timestamp--ti...

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

#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/21/docs/api/java.base... - this is also where the wonky zero-indexed month value comes from. Note that Java deprecated all versions of the constructor other than the one taking a millisecond value or nothing, which JS can't do for backwards compatibility reasons.

Hopefully `Temporal` will solve these problems but how long that spec has been in the works should tell you how difficult this is to get right when anything you put on the web is forever.

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

#49

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

Uh, TIL. As a non American it was known to me that Americans use the YDM format but I had no idea slashes vs dashes carried meaning for that.

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

#50

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

I'm not American but I lived in the US for 10 years.

I had never seen Y/D/M. I almost never see American use Day/Month order to begin with, let alone Y/D/M.

Post reply on HN