Re:New Date("WTF") – How well do you know JavaScript's Date ...
by wewtyflakes on Sunday July 13, 2025 @02:22AM
(#44547968)
Why is nothing more important than backwards compatibility between disparate languages written in different contexts for different contexts?
Re:New Date("WTF") – How well do you know JavaScript's Date ...
by porridgeraisin on Monday July 14, 2025 @01:17AM
(#44556713)
That javascript chose to offset from 1900 was simply because every system back then used to, including Java.
Once that had been done, future versions of javascript had to maintain the same behaviour. This is where I'm using the backwards compatibility argument.
Re:New Date("WTF") – How well do you know JavaScript's Date ...
by wewtyflakes on Monday July 14, 2025 @04:52PM
(#44565127)
Seems like JS could have called it `getYearOffset1900`, or `getYearOffet`, etc, rather than `getYear`.
Re:New Date("WTF") – How well do you know JavaScript's Date ...
by porridgeraisin on Friday July 18, 2025 @10:56AM
(#44605349)
Agreed. What I've read is that they basically duplicated the Java API, which had getYear()
I suppose the offset method was really quite entrenched so no one thought to special case that function, instead special casing the "2025" returning getFullYear()
It is just programmer education to know to add 1900 to years when using struct tm and also to use getFullYear() in JS.