There's a larger design issue here that becomes clearer if you think of timezones as something more like temporal reference frames. Every date and/or time is relative to something; it's just a question of whether that reference is explicit or implicit, and if it's implicit then how does it get resolved? Your original code (inadvertently) used a UTC day: T00:00:00Z -> T24:00:00Z. Your new code uses a day in an implici…
It's worse than this: it's not just "what's my (app developer) reference frame for time in this app" but rather "what is the user's reference frame", and that is a thing that changes even for a single user. I have been in a paper-notebook-calendar mode for a while now, but every time I've dealt with an electronic calendar app, it's been a struggle, because sometimes I write down a time relative to the time zone I'm i…
JavaScript decided my day starts at 9am
21–30 of 47 posts
Re: JavaScript decided my day starts at 9am
#22I have all records stored in timestampz(3), but I have no idea if what I'm doing is best practice or how to audit said functions. Using luxon at the moment, but a guide or blog post for best practices would help put my mind at ease if anyone has one. I know dates as a library are complex, but the UX managing them isn't much better.
Re: JavaScript decided my day starts at 9am
#23From the post: I knew that new Date('YYYY-MM-DD') sets the time to midnight. What I didn’t know was that it sets it to midnight in UTC. This is all the Date constructor could do in this use-case. There is no timezone specified and assuming one other than UTC could easily result in undefined behavior. I think a better "lesson learned" in this case is to remove all ambiguity from datetime types by internally using only…
There is no ambiguity. The Date constructor provides a timezone offset: myDate.getTimezonOffset(); It outputs the number of minutes different from UTC time. I use this to display server time in both server local and zulu (UTC) via a WebSocket broadcast every 950ms.
> There is no ambiguity.
The ambiguity I referenced was regarding program logic, not how `Date` operates when given only the year/month/date part of an instant. Perhaps I should have said instead:
I think a better "lesson learned" in this case is to
remove all ambiguity when using datetime types
by internally using only UTC representations for
calculations ...
And, yes, I do see the irony in this. :-)Re: JavaScript decided my day starts at 9am
#24Since Japan has exactly one timezone and most services are intended for use within Japan, many Japanese programmers are unaware of timezone-related logic. I've frequently encountered Japanese sites store dates as OffsetDateTime instances (rather than UTC Instants), and have frequently seen subtle bugs, like a web app's backend returning UTC+9 timestamps, and then subsets of the frontend format the date according to t…
Nothing wrong with this. Operating in one timezone only simplifies things, no need to overcomplicate it.
Re: JavaScript decided my day starts at 9am
#25Since Japan has exactly one timezone and most services are intended for use within Japan, many Japanese programmers are unaware of timezone-related logic. I've frequently encountered Japanese sites store dates as OffsetDateTime instances (rather than UTC Instants), and have frequently seen subtle bugs, like a web app's backend returning UTC+9 timestamps, and then subsets of the frontend format the date according to t…
Nothing wrong with this. Operating in one timezone only simplifies things, no need to overcomplicate it.
Re: JavaScript decided my day starts at 9am
#26I'm building a fairly large SaaS product that will have global users and show financial reporting across different regions. Nothing gives me more anxiety as a relatively new developer than storing and recalling date/time values from my Postgres database, being converted to/from/being displayed in my app. I have all records stored in timestampz(3), but I have no idea if what I'm doing is best practice or how to audit…
maybe there are some cases where you want to store the timezone (e.g. you've displayed a datepicker and the user has expressly entered a timezone)--but normally you'll save headache by storing everything in zulu time.
if storing the timezone is important for those transactions, then I could potentially see that as warranting storage with a timezone as well.
basically, ask 'if the timezone matters' with respect to the information being encoded. if it's just for display purposes and can be ignored, then KISS.
Re: JavaScript decided my day starts at 9am
#27Earlier quoted context omitted.
Nothing wrong with this. Operating in one timezone only simplifies things, no need to overcomplicate it.
Obvious potential failure case: Japanese citizens who are travelling abroad.
Most businesses do not care, because it's harder to counter bots when allowing overseas traffic. Moreover, the number of Japanese who leave the country are a small fraction. For reference, the percentage of Japanese who hold a passport is 17%. A small fraction of the 17% represent students studying abroad (or other long-term stays).
There's enough internal demand that people travelling abroad (or studying abroad) are considered edge cases worth ignoring. As surreal as this sounds, this is the current situation.
Re: JavaScript decided my day starts at 9am
#28I'm building a fairly large SaaS product that will have global users and show financial reporting across different regions. Nothing gives me more anxiety as a relatively new developer than storing and recalling date/time values from my Postgres database, being converted to/from/being displayed in my app. I have all records stored in timestampz(3), but I have no idea if what I'm doing is best practice or how to audit…