`new Date('0')` in javascript returns 2000-01-01 but `new Date(0)` returns 1970-01-01 🤯
Follow

@thatguyoverthere
That would probably be the case in many languages as it's char (or single-character string) vs integer (or other numeric type), but why the fuck is it 2000-01-01 in particular? WTF indeed 🤯

@m0xee yeah the particular date was what was strange. Upon closer inspection it's specifically 2000-01-01T05:00:00.000Z so the turn of the century in America/New_York timezone
@m0xee It's weird because it does parse the strings before creating the date object, and the number of 0s changes the output

```
> new Date(0)
1970-01-01T00:00:00.000Z
> new Date('1970')
1970-01-01T00:00:00.000Z
> new Date('0')
2000-01-01T05:00:00.000Z
> new Date('00')
2000-01-01T05:00:00.000Z
> new Date('000')
2000-01-01T05:00:00.000Z
> new Date('0000')
0000-01-01T00:00:00.000Z
```

An API I am interacting with provides an invalid date string of '0000-00-00T00:00:00Z' which is why I am feeding it junk in the first place. It could just return false or null or an empty string instead of something formatted like a date that doesn't parse out but hey.

@thatguyoverthere
This language is absolute hell!
With lots of quirks that work this way "just because" — as someone thought "why the hell not?" at some point in the past and now no one dares to touch it and bring some sanity into it — as it might break something in the decade old codebase of some project, so more newer quirks keep growing out of old ones just to expect more or less predictable behavior even though to those unfamiliar it doesn't make any sense at all 😩

Sign in to participate in the conversation
Librem Social

Librem Social is an opt-in public network. Messages are shared under Creative Commons BY-SA 4.0 license terms. Policy.

Stay safe. Please abide by our code of conduct.

(Source code)

image/svg+xml Librem Chat image/svg+xml