JavaScript decided my day starts at 9am
senhongo.com
JavaScript decided my day starts at 9am
1–10 of 47 posts
Re: JavaScript decided my day starts at 9am
#2> When the time zone offset is absent, date-only forms are interpreted as a UTC time and date-time forms are interpreted as a local time
Fun!
Obligatory joke:
Brendan Eich created JavaScript in 10 days. And we’ve been fixing it ever since.
Re: JavaScript decided my day starts at 9am
#3Re: JavaScript decided my day starts at 9am
#4Re: JavaScript decided my day starts at 9am
#5Re: JavaScript decided my day starts at 9am
#6My rule of thumb is: keep all business logic in UTC, and convert from/to local time as close to the UI as possible
It obviously depends on your use case but I find most time operations are often easier to deal with as pure mathematical operations. I will reach for Date when I need to deal with weird stuff like the day of the week but having burned through so many footguns with what I consider the worst DateTime API I have ever dealt with in any language, I will do anything I can to avoid using it.
Some libraries like date-fns can help here, but can't always bring in new deps easily. I hope the new temporal API fixes things.
Re: JavaScript decided my day starts at 9am
#7Re: JavaScript decided my day starts at 9am
#8Re: JavaScript decided my day starts at 9am
#9Your original code (inadvertently) used a UTC day: T00:00:00Z -> T24:00:00Z. Your new code uses a day in an implicit timezone, which gets resolved by the client (to its local time). So, if you send that dashboard to someone in Singapore or Australia, their day is going to be an hour off compared to what you see.
Ultimately, the design issue is: when someone says "Tuesday", do they mean Tuesday in their local time? Tuesday in Japan? Tuesday in the location of their company HQ? Tuesday in the timezone where they do the most business?
I think a lot of the reason people get mad about timezones is because they don't think clearly about their reference frames from the beginning, which leads to getting caught up in implicit time spaghetti later on.
Re: JavaScript decided my day starts at 9am
#10I've also encountered games where device local time results in bugs when certain features are gated to durations within Japanese Standard Time. For one particular game, I contacted support and the response was similarly "this service is intended for use within Japan; please ensure your device time is set to Japanese Standard Time." The support representative actually went further and told me, "if you are using this service outside of Japan, then we cannot make any guarantees on [the app's] behavior or resolve issues."
To most programmers in the US or Europe, storing all dates as UTC and localizing datetimes in the frontend may seem like "common sense", but this is essentially 異文化 to many Japanese programmers, for lack of a better way to phrase it.