News for hackers. Stuff that matters.
Re:Temporal: Getting started with JavaScript's new date time... by raxxorrax on Monday June 28, 2021 @09:50AM (#27661942)
Didn't find to much info on arithmetic support, although it is mentioned.

However, I hate working with dates because many APIs make question about dates a slog.

Consider the following for the poor people on the dark side of the planet (UTC + something). If any application only saves the date and not the time and you have dates like 2021-06-28T00:00:00 or something like that.

Now it gets saved in a DB as 2021-06-27Z23:00:00, because the user lives in UTC+1-land. It is correct but makes my blood boil and propably causes a lot of errors, even in apps that set their time zone correctly. How often have I seen implementations that just /(.*)T.*/ match the date and create a bug.

I have no solution for this, but I wasted too much time on problems like this. Such errors also notoriously evade unit tests...

This seems decent from a quick look. But let us be honest, it has to compete with moment.js, not with Date().

Re:Temporal: Getting started with JavaScript's new date time... by 015a on Monday June 28, 2021 @01:32PM (#27664818)
I've personally worked on issues stemming from this; situations where the date is important, but not the time, such as correctly reporting when it is someone's birthday.

One of the earliest axioms we drill into programmers is "use UTC, use date-time types". Don't store dates as strings, use your database's DateTime type.

If your database has a Date sans-Time type, use that. But many databases don't, and that's where the axiom starts breaking down, because its very natural to say "well, I'll use the next best thing, a DateTime type". But this is wrong! Its far, far better to simply use a YYYY-MM-DD string. I cannot stress how much better this is, but its not obvious why its better to someone who has had that axiom drilled into their heads, and has never ran into this situation before.

Re:Temporal: Getting started with JavaScript's new date time... by squeaky-clean on Monday June 28, 2021 @06:35PM (#27669162)
Worst case of this I've personally had to fix was an airline where you couldn't purchase tickets if you lived anywhere with a negative time zone offset. They're a small European carrier so it was never a very big issue for them, and all the developers and management were in Europe so they never noticed it first hand.

Basically when you tried to purchase a ticket, their frontend would take the date-of-flight, and adjust it by the user's timezone. So a ticket for 2015-01-30 00:00 would become 2015-01-29 20:00, or whatever. The dates in the request did not match what was expected for your booking code, and 500 error.

Re:Temporal: Getting started with JavaScript's new date time... by valtism on Tuesday June 29, 2021 @12:01AM (#27671615)
As a developer in Australia, I have made these sorts of errors that I didn't notice until my colleagues in the US picked them up. I am actually very happy that America is in a negative timezone, because I believe these errors would be a lot more prevalent if they were not.
Re:Temporal: Getting started with JavaScript's new date time... by jkaptur on Monday June 28, 2021 @02:00PM (#27665240)
Yeah, "always use UTC" is overrated. It's useful for things that have happened, but quickly becomes unintuitive for things that will happen - including birthdays, meetings, ...
Re:Temporal: Getting started with JavaScript's new date time... by mattmanser on Monday June 28, 2021 @02:51PM (#27666049)
It can even become wrong for future dates. Always use UTC is a broken, bad rule for future dates, it only makes sense for things that have already happened.

As for how it breaks, you have a booking for 8pm the day after the start of summer time. You stored the date/time in UTC. Government changes the start of summer time. Your database now thinks it's at 7pm because it uses UTC.

Here's some examples:

https://codeofmatt.com/on-the-timing-of-time-zone-changes/

Also the EU is seriously debating getting rid of clock changes, and it comes up in the UK semi-regularly.

Your database will not fix your bad data when that happens.

Re:Temporal: Getting started with JavaScript's new date time... by elgaard on Monday June 28, 2021 @07:35PM (#27669731)
Yes, timezones do not at all work with reservations for physical objects.

I work on a registration and reservation system for rowing boats in my rowing club https://github.com/dsroklub/roprotokol

The only time that matters is whatever the clock in the clubhouse shows (Danish time) If you sign out a boat from the UK (or more realistically from a laptop that thinks it is in the UK) at 14:00 it is still 14:00 Danish time. This is surprisingly difficult to achieve with JS Date object, browsers and popular JS components.

So the Temporal Plain time looks promising.

And especially the explicit timezones. Because even without timezone you need to handle DST. For example my system needs to know that if you start a 3 hour trip at midnight a certain day in the spring, you are expected back at 04:00.

I just hope that browsers and components will support is properly.

Re:Temporal: Getting started with JavaScript's new date time... by stickfigure on Monday June 28, 2021 @07:27PM (#27669670)
Even more common:

* Your meeting is scheduled for 2pm tomorrow.

* Oh oh! Your meeting got bumped to the next day.

* Daylight savings switched overnight.

Some things are measured in relative time. Some things are measured in absolute time. Never confuse the two in your database.

Re:Temporal: Getting started with JavaScript's new date time... by no-s on Tuesday June 29, 2021 @08:57AM (#27675141)
> Your database will not fix your bad data when that happens.

Because it’s not bad data, HaHaOnlySerious. I tell developers that if the database attribute accepts a value it must be in the domain of allowable values. Often people refuse check constraints in order to avoid expressing business logic in the database.

Re:Temporal: Getting started with JavaScript's new date time... by GormanFletcher on Tuesday June 29, 2021 @07:42PM (#27683217)
The GP's example doesn't involve invalid datetimes. The datetimes aren't out of bounds or invalid in any way that a check constraint would detect. They've just become factually incorrect ("bad data"), because they are derived data that wasn't updated when the derivation rules changed (i.e., regulatory changes).

If you're storing future datetimes that semantically represent wall clock time, you need to store the locale time plus the full time zone (such as America/New_York) so that your program does the right thing in response to any common regulatory changes that happen after you store the value. Storing the time zone abbreviation (e.g., EST) is inadvisable, as computers sometimes care whether you asked for EST vs EDT. Storing the time offset (e.g., -500) is incorrect, as it has the same pitfalls as storing UTC - you're precomputing the locale's expected time offset at storage time, and your data won't automatically be corrected if time regulations change.

If you're storing historical timestamps, UTC is fine because you can safely convert it to whatever time zone you want to display, knowing that changes to time zone / DST regulations tend not to affect the past.

Re:Temporal: Getting started with JavaScript's new date time... by no-s on Wednesday June 30, 2021 @06:36PM (#27694311)
> If you're storing future datetimes that semantically represent wall clock time, you need to store the locale time plus the full time zone (such as America/New_York) so that your program does the right thing in response to any common regulatory changes that happen after you store the value.

At this point in the process first normal form flies out the window. Trying to generalize too much can lead you down some weird garden paths. If it looks like you need a function to validate an prospective column value then you probably need to model the value as a relation corresponding to the function parameters. Then you can make it into a foreign key constraint and get on with your project.

I truly appreciate the efforts of those who attempt to expand the utility of datetime value representation to perfect a wider variety of denotational semantics. But with a relational model it may be better to delegate to simpler abstraction sufficient to the specific case.

Re:Temporal: Getting started with JavaScript's new date time... by mulmen on Monday June 28, 2021 @03:48PM (#27666913)
But would using local time help in this case? For example, what if the future event is something like the solstice?

It's usecase dependent so it seems like the application should deal with this, at which point persisting in UTC is still a reasonable choice.

Re:Temporal: Getting started with JavaScript's new date time... by DasIch on Monday June 28, 2021 @05:28PM (#27668401)
When you schedule an event in the future like “meet me at 14:00 in cafe foo”, this means local time and it’s going to mean 14:00 local time even when the timezone changes.

If you store this in UTC and the timezone changes, you end up converting to the wrong time.

So for future events you should store local time with a location you can map to a timezone.

Re:Temporal: Getting started with JavaScript's new date time... by mulmen on Monday June 28, 2021 @07:52PM (#27669851)
The solstice is based on astronomical phenomena. If you store it in UTC it will always be right.
Re:Temporal: Getting started with JavaScript's new date time... by funcDropShadow on Tuesday June 29, 2021 @08:38AM (#27674963)
Unless there is a leap second scheduled on short notice or you install the updated tz database rather late. For astronomical events or long term measurements (think CERN) there is astronomical time, which does not add leap seconds.

But if you want to have precise date time far in the future you must not use UTC based milliseconds representations unless you want to check for necessary database migrations every time the time zone definitions change.

Re:Temporal: Getting started with JavaScript's new date time... by mulmen on Tuesday June 29, 2021 @05:09PM (#27681767)
If you store zoned time in UTC then the zones or UTC change then the time can be formatted correctly in the future.

My point in mentioning the solstice is that while some events are at “2pm”, others are “when something happens”.

Sure, UTC is not suitable for conducting astronomy. It is suitable for working with human friendly times, since it is the foundation of timezones.

Re:Temporal: Getting started with JavaScript's new date time... by nicoburns on Monday June 28, 2021 @06:23PM (#27669040)
Yep! It sounds like overkill, but the suggestion I've seen that seemed to cover all bases was to store:

(1) The time in the local timezone (+ the timezone itself) (2) The UTC conversion (3) The version of the IANA database used to compute (2)

Then you can use (2) the UTC time for most computations/queries, but if a timezone changes then you can use (3) to tell which UTC dates need to be updated, and (1) to recompute the new correct version of (2).

Re:Temporal: Getting started with JavaScript's new date time... by mattmanser on Monday June 28, 2021 @06:34PM (#27669153)
That seems like overkill for most apps. Better to just store the date/time without timezone, and either the windows or linux timezone name of the location (which has far more specificity than the ISO 8601 offset). Then calculate the actual time on the fly when pulling it out of the DB.

No mucking around with IANA databases, everything's easy to program, server usually keeps itself up-to-date.

Re:Temporal: Getting started with JavaScript's new date time... by dheera on Monday June 28, 2021 @05:52PM (#27668673)
Personally I solve this problem by just doing everything in UTC. All my clocks, calendars, phones, everything read UTC.

"Always use UTC" works if you really, really always use UTC.

Re:Temporal: Getting started with JavaScript's new date time... by thewakalix on Monday June 28, 2021 @09:19PM (#27670532)
What about interfacing with the outside world, which doesn't always use UTC?
Re:Temporal: Getting started with JavaScript's new date time... by dheera on Monday June 28, 2021 @09:56PM (#27670783)
Translate. But frankly I often still use UTC to coordinate with people, especially when coordinating meetings with people in 3 timezones.
Re:Temporal: Getting started with JavaScript's new date time... by BurningFrog on Monday June 28, 2021 @10:07PM (#27670855)
Always use UTC for timestamps.

Never use UTC for dates. Like OP says, a simple YYYYMMDD string is better.

Re:Temporal: Getting started with JavaScript's new date time... by drenvuk on Tuesday June 29, 2021 @12:15AM (#27671699)
This is wrong depending on the use case and where the user is and where the user might be going.
Re:Temporal: Getting started with JavaScript's new date time... by mianos on Monday June 28, 2021 @07:06PM (#27669470)
Always use UTC is not overrated. It is true, it may be overrated if you don't store time with your date or don't have a datetime type in your database (that makes me think WTF). You are always better using UTC to store dates if you have a datetime type.
Re:Temporal: Getting started with JavaScript's new date time... by strbean on Monday June 28, 2021 @02:09PM (#27665382)
This might be silly, but I kind of wish Date-with-Timezone types existed. It would be nice to be able to take a date and ask "Is does timestamp X fall within date Y", where Y is a calendar day in a particular place.
Re:Temporal: Getting started with JavaScript's new date time... by bmuon on Monday June 28, 2021 @03:19PM (#27666478)
You don't need a zoned date. You can invert the question and ask if a zoned datetime falls within a plain date.

Temporal is very well designed thanks to building on years of prior art. Give it a try and you'll realize that it leads you to ask those questions the right way.

Re:Temporal: Getting started with JavaScript's new date time... by _nub3 on Monday June 28, 2021 @04:45PM (#27667862)
This is why i use microtime (epoch with miliseconds) over any database supported DateTime thingy. It is supported everywhere out of the box.
Re:Temporal: Getting started with JavaScript's new date time... by BurningFrog on Monday June 28, 2021 @10:09PM (#27670876)
I've had this discussion with many confused developers.

Seems like everyone has to stub their own toe on this to get it.

Re:Temporal: Getting started with JavaScript's new date time... by alerighi on Monday June 28, 2021 @04:01PM (#27667109)
I don't get why inventing some other ways of storing dates that are not RFC 3339 strings.
Re:Temporal: Getting started with JavaScript's new date time... by 015a on Monday June 28, 2021 @04:42PM (#27667795)
Multiple reasons. First, the DateTime type in a typical database isn't even an RFC-3339 string; its a unix timestamp. That's it; an unsigned integer. This is very space efficient; far more-so than a string. So, then, why the indirection; why not just use the integer type directly? It communicates to the database engine the intent of the data stored, so the database can do useful things like, for example, time-based queries, interfacing with that integer in more human friendly ways when writing queries, displaying it in a more friendly way... its a low-cost abstraction, generally.

Except, there is the cost intrinsic to this discussion, where going back to strings makes sense. That doesn't mean that decision comes with no cost. If you store someone's birthday as "1990-02-05", then need to answer the question "who has birthdays in the next month", that's actually essentially impossible to do in practically any database query engine. You have the problem of both ignoring the year field of that string (ok, so, maybe we just store "02-05" because the year doesn't matter for birthdays, moreso just 'dates of birth', we can denormalize)... but even beyond that, the closest most if not all engines could get is generating an array of every upcoming day in application code (02-05, 02-06, 02-07, etc) then matching on each. Alternatively, just sort on the field (sans year) then filter in application code, but that's also not happening in the database, which has negatives, and moreover, this would suddenly start failing across year boundaries, but you can special-case that by running a second query starting at 01-01 if the first one didn't return enough results...

There's no easy solution. Time is just really hard. Its good to have as many tools as possible in your belt, but with that you have to know when to reach for one versus another. There isn't one solution to any of these problems.

Re:Temporal: Getting started with JavaScript's new date time... by lootsauce on Monday June 28, 2021 @04:55PM (#27667990)
This. I have through much pain embraced this approach.
Re:Temporal: Getting started with JavaScript's new date time... by branko_d on Tuesday June 29, 2021 @01:18AM (#27672087)
It's better to use a native date/time with a CHECK that ensures that the time portion is 0.

You'll have to do a CHECK on the YYYY-MM-DD string anyway to protect your database from bad data, so why not just do it on the native type?

The native type is likely to be more compact, performant, consistent across the database (with strings, some columns may be YYYY-MM-DD, some may be YYYY.MM.DD etc.) and more readily convertible to the client's type system.

Re:Temporal: Getting started with JavaScript's new date time... by rauschma on Monday June 28, 2021 @10:03AM (#27662109)
The Temporal cookbook has more information on time arithmetic: https://tc39.es/proposal-temporal/docs/cookbook.html#arithme...
Re:Temporal: Getting started with JavaScript's new date time... by raxxorrax on Monday June 28, 2021 @10:19AM (#27662312)
That looks very promising, thank you.
Re:Temporal: Getting started with JavaScript's new date time... by sparsely on Monday June 28, 2021 @12:55PM (#27664337)
The Temporal proposal is dramatically better than moment.js (and Luxon, the better version of moment). It accurately models a much wider range of time based concepts, and draws on (mostly just copies) the last 30 years of developments in this space from other languages (mostly Java)
Re:Temporal: Getting started with JavaScript's new date time... by rendall on Monday June 28, 2021 @10:04AM (#27662116)
> But let us be honest, it has to compete with moment.js, not with Date().

Moment.js is deprecated: "Moment.js is a legacy project, now in maintenance mode. In most cases, you should choose a different library."

https://github.com/moment/moment/#project-status

Re:Temporal: Getting started with JavaScript's new date time... by dstick on Monday June 28, 2021 @11:23AM (#27663100)
That's only half the story. It's "deprecated" because it's done. There's nothing more to add, fix or improve in the eyes of the maintainer. What a nice place to end up in:

_"We now generally consider Moment to be a legacy project in maintenance mode. It is not dead, but it is indeed done."_

https://momentjs.com/docs/

Re:Temporal: Getting started with JavaScript's new date time... by paxys on Monday June 28, 2021 @12:00PM (#27663564)
You skipped the line right after this which completely changed the meaning:

> We recognize that many existing projects may continue to use Moment, but we would like to discourage Moment from being used in new projects going forward.

Re:Temporal: Getting started with JavaScript's new date time... by dstick on Monday June 28, 2021 @01:41PM (#27664910)
Fair enough, but the parent mentioned that without quoting this part. So I just posted the other half. Regardless, you’re right - new projects shouldn’t use it because of unknown future problems.
Re:Temporal: Getting started with JavaScript's new date time... by rendall on Monday June 28, 2021 @12:20PM (#27663851)
> There's nothing more to add, fix or improve in the eyes of the maintainer. What a nice place to end up in

What a strange thing to say. Baffling.

It's deprecated because programming standards have changed, the team agrees with those standards and nevertheless feels it would be too much work to incorporate them. Not "there's nothing more to add" but "we choose to prioritize stability over new features"

Re:Temporal: Getting started with JavaScript's new date time... by blowski on Monday June 28, 2021 @11:42AM (#27663338)
Wow! Next time someone says "no piece of software is ever finished" I'll know where to send them.
Re:Temporal: Getting started with JavaScript's new date time... by leotaku on Monday June 28, 2021 @12:44PM (#27664174)
Note that there exists a spiritual successor to Moment.js in Luxon[1]. The creator was a Moment maintainer and it lives under the Moment project umbrella.

1: https://moment.github.io/luxon/

Re:Temporal: Getting started with JavaScript's new date time... by neals on Monday June 28, 2021 @12:54PM (#27664327)
Also check out dayjs
Re:Temporal: Getting started with JavaScript's new date time... by enlyth on Monday June 28, 2021 @12:59PM (#27664396)
I've been very happy with date-fns, picked it up after hearing good feedback from others: https://date-fns.org/
Re:Temporal: Getting started with JavaScript's new date time... by spacehunt on Tuesday June 29, 2021 @04:18AM (#27673238)
date-fns's insistence on using the native Date object makes handling timezones horrible and error-prone though. Luxon is much better in this regard.
Re:Temporal: Getting started with JavaScript's new date time... by trulyme on Monday June 28, 2021 @05:25PM (#27668355)
I found its interface inconsistent and unintuitive, especially compared to moment.js and day.js. Still better than Date though. :)
Re:Temporal: Getting started with JavaScript's new date time... by raxxorrax on Monday June 28, 2021 @10:19AM (#27662307)
True, but I think it will be some death of author kind of story.

Nevertheless the handling has to be at least on a similar level.

Re:Temporal: Getting started with JavaScript's new date time... by mellavora on Monday June 28, 2021 @01:19PM (#27664636)
Moment is depreciated because all of its functions were moved to date-fns, which lets you import single functions.
Re:Temporal: Getting started with JavaScript's new date time... by slaymaker1907 on Monday June 28, 2021 @01:16PM (#27664579)
The correct answer is that you should save it as 2021-06-28 with no time component. I get frustrated with KeyPass because it saves password expiration datetimes and not dates which is incredibly inconvenient when you go between timezones a lot.
Re:Temporal: Getting started with JavaScript's new date time... by dheera on Monday June 28, 2021 @06:14PM (#27668931)
> Temporal does not support parsing human-readable strings.

Well shit, that's one of the biggest things I want from a time library. There are about 15 different forms of human readable string formats that various APIs give you in their JSON responses and if they don't solve that, they haven't solved the biggest pain point.

I guess congratulations for not solving the problem and instead making Javascript even more complicated to use by introducing yet another incomplete date library that skirts around perhaps the most important feature and which millions of hippie JS devs will jump on the bandwagon to use.

Re:Temporal: Getting started with JavaScript's new date time... by symlinkk on Monday June 28, 2021 @07:33PM (#27669711)
If you’re parsing human readable strings to determine a datetime in your codebase you messed up somewhere. The user should select a datetime with a picker that uses a calendar and dropdown menus (no freeform text input). Everywhere from then on in your code you should pass it around using some standard, either as a UNIX timestamp or ISO8601.
Re:Temporal: Getting started with JavaScript's new date time... by dheera on Monday June 28, 2021 @07:53PM (#27669859)
Well no, the problem is I very frequently have to interface with APIs that give me human readable time strings only. Those APIs were not written by top quality engineers and I often have no other choice or way to interface with those systems.

Also you mention ISO-8601 but this document does not even describe how to input an ISO-8601 string.

Re:Temporal: Getting started with JavaScript's new date time... by filoeleven on Monday June 28, 2021 @08:58PM (#27670364)
…until you’re working on an app for servicing companies, shipping departments, etc. where on some forms nearly 1/2 of the input fields can be dates. Then your users hate you because they can’t just tab > type > tab to enter a date.

I agree with you on the rest though. And I would love to be able to enforce ISO 8601 for text entry of dates.

Re:Temporal: Getting started with JavaScript's new date time... by mastazi on Monday June 28, 2021 @06:51PM (#27669325)
I use a calories counter app called MyNetDiary and I live in Sydney (UTC+10:00), if I want to change my calories budget I can only do it in the evening, or otherwise the change will apply to the previous day.
Re:Temporal: Getting started with JavaScript's new date time... by mastazi on Tuesday June 29, 2021 @01:31AM (#27672163)
PS except from this one issue I'm a very happy customer, it's a great app :-)
Re:Temporal: Getting started with JavaScript's new date time... by EMM_386 on Monday June 28, 2021 @04:00PM (#27667102)
> If any application only saves the date and not the time and you have dates like 2021-06-28T00:00:00 or something like that.

I literally just spent hours going around a code base fixing this exact problem.

Our back-end is a legacy, 20+ year old database where it was decided to save dates without a timezone.

console.log(new Date("2011-09-24"));

is:

Fri Sep 23 2011 20:00:00 GMT-0400 (Eastern Daylight Time)

These dates were all "thought" to be EST, not UTC. Good times.

More fun examples here:

https://stackoverflow.com/a/31732581/154603

Re:Temporal: Getting started with JavaScript's new date time... by drenvuk on Monday June 28, 2021 @10:45AM (#27662662)
>Now it gets saved in a DB as 2021-06-27Z23:00:00

Why would you ever do this? Save it as a JSON date. coolDate.toJSON() would give a timezoned human parseable date. Just parse it back to the users locale with a built in Date constructor. You can do milliseconds UTC but someone like my younger stupid self would screw it up like most people.

Re:Temporal: Getting started with JavaScript's new date time... by cbsmith on Monday June 28, 2021 @12:28PM (#27663960)
If it's only a date, it probably should be days since the epoch.
Re:Temporal: Getting started with JavaScript's new date time... by aljarry on Monday June 28, 2021 @12:53PM (#27664309)
But starting from which timezone?
Re:Temporal: Getting started with JavaScript's new date time... by ulrikrasmussen on Monday June 28, 2021 @01:15PM (#27664567)
Irrelevant for dates. Dates do not refer to a point on the global timeline.
Re:Temporal: Getting started with JavaScript's new date time... by cbsmith on Wednesday June 30, 2021 @03:16AM (#27685824)
Dates are set against calendar which in turn is set against hourly increments that are offset by local time zones. There is the infamous AoE or "Anywhere on Earth" time zone which can be used to say things like "we won't start until after the 16th Anywhere on Earth", meaning it will at least be the 17th in all timezones before the work gets started, but even in that case, you're referring to an implicit time zone.
Re:Temporal: Getting started with JavaScript's new date time... by aljarry on Tuesday June 29, 2021 @10:24AM (#27676191)
What do you mean? In Auckland _right now_ it's Wednesday, 30th of June, while in Los Angeles it's Tuesday, 29th of June.
Re:Temporal: Getting started with JavaScript's new date time... by cbsmith on Wednesday June 30, 2021 @03:08AM (#27685793)
The epoch is a specific moment in all time zones. It didn't happen at one moment in Greenwich and then another moment twelve hours later in Auckland & Wellington. Any subsequent moment can be represented based on the amount of time that has passed since that moment.

No "which time zone" confusion necessary.

Re:Temporal: Getting started with JavaScript's new date time... by aljarry on Wednesday June 30, 2021 @06:14AM (#27686815)
Thanks, I get it now :)
Re:Temporal: Getting started with JavaScript's new date time... by cbsmith on Wednesday June 30, 2021 @01:47PM (#27691456)
Thank you for restoring my faith that I can occasionally effectively communicate on social media!
Re:Temporal: Getting started with JavaScript's new date time... by recursive on Monday June 28, 2021 @01:18PM (#27664618)
JSON date is not a thing.
Re:Temporal: Getting started with JavaScript's new date time... by drenvuk on Monday June 28, 2021 @03:56PM (#27667031)
Sure, my bad. You know what I mean though.
Re:Temporal: Getting started with JavaScript's new date time... by recursive on Monday June 28, 2021 @06:38PM (#27669198)
I really actually don't. Dates in JSON are going to require you to pick a serialization form. ISO8601 seems like a totally reasonable pick. So if not that, then what? Could you give an example?
Re:Temporal: Getting started with JavaScript's new date time... by drenvuk on Monday June 28, 2021 @07:08PM (#27669496)
while developing my project I ignored what the officially named format was and simply checked what converted properly between three browsers.

Safari: "2021-06-28T22:59:18.366Z"

Chrome: "2021-06-28T23:01:09.131Z"

Firefox: "2021-06-28T23:00:14.385Z"

The three that I strive to support all utilize this format. YYYY-MM-DDTHH:mm:ss.sssZ. Looking on MDN this seems to call toISOString() which returns a simplified extended ISO format date.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Re:Temporal: Getting started with JavaScript's new date time... by josephg on Tuesday June 29, 2021 @12:09AM (#27671664)
> I ignored what the officially named format was

You ignored the officially named format and instead settled on the officially named format. Those are ISO8601 timestamps, specified in UTC time. (The Z at the end means there's (Z)ero timezone offset from UTC). If you're going to talk about a standard, its worth knowing its name.

Re:Temporal: Getting started with JavaScript's new date time... by drenvuk on Tuesday June 29, 2021 @12:37AM (#27671822)
I don't care what the name of something is so long as it does what I want and has a form that I can understand and utilize.
Re:Temporal: Getting started with JavaScript's new date time... by BurningFrog on Monday June 28, 2021 @10:13PM (#27670910)
Those are timestamps, not dates.

Each of them fall on two separate dates, depending on time zone.

Re:Temporal: Getting started with JavaScript's new date time... by drenvuk on Monday June 28, 2021 @11:56PM (#27671591)
This is why dates are such an issue.

A timestamp is the number of seconds or milliseconds or units like 1624938650 seconds from epoch UTC. What I posted above are human parseable datetimes in ISO 8601. Each of them is a point in time that depending on the locale and tz fall on two separate dates but the most important aspect is that it doesn't matter whether I'm using them in my DB or on a user's machine in a different locale and tz. That's the point.

Re:Temporal: Getting started with JavaScript's new date time... by BurningFrog on Tuesday June 29, 2021 @04:46PM (#27681494)
I don't think we disagree?
Re:Temporal: Getting started with JavaScript's new date time... by afavour on Monday June 28, 2021 @02:27PM (#27665654)
That works great when every interaction you make with the data is in JS. But less so if you want to, say, run manual SQL queries from time to time.
Re:Temporal: Getting started with JavaScript's new date time... by drenvuk on Tuesday June 29, 2021 @12:51AM (#27671899)
They're sortable. I don't see what the issue is. Can you explain?
Re:Temporal: Getting started with JavaScript's new date time... by alach11 on Monday June 28, 2021 @12:53PM (#27664305)
Maybe a better choice would be to use a DateTimeOffset.
Re:Temporal: Getting started with JavaScript's new date time... by shadowgovt on Monday June 28, 2021 @12:01PM (#27663584)
The real issue is that time is actually a complicated subject that everyone assumes is easy because it's so ubiquitous.
Re:Temporal: Getting started with JavaScript's new date time... by beardyw on Monday June 28, 2021 @02:16PM (#27665472)
Dates were invented in case anyone thought programming was fun.
Re:Temporal: Getting started with JavaScript's new date time... by qwertox on Monday June 28, 2021 @01:45PM (#27664987)
The user doesn't live in UTC+1-land. He lives in "Europe/London" or "America/Los_Angeles", because this way DST is also considered.

I've settled with storing Zulu time and in a separate field the timezone offset of the event in seconds.

Re:Temporal: Getting started with JavaScript's new date time... by brundolf on Monday June 28, 2021 @04:07PM (#27667222)
I used to work on a web application where showing correct time stamps was extremely important, so I set my system-wide time zone to Mumbai so that TZ-related bugs would be really obvious in testing
Re:Temporal: Getting started with JavaScript's new date time... by tomp on Monday June 28, 2021 @02:53PM (#27666082)
The original mistake you did was let someone else handle the timezone conversion. You should probably always default to storing UTC-normalized timezoneless datetimes (there's of course a number of exceptions, but generally "an instant" in the past should be translated into UTC before being stored into the database... with future dates/times, it's more ambiguous, but in any case, you should be doing the TZ conversion yourself).
Re:Temporal: Getting started with JavaScript's new date time... by mabbo on Monday June 28, 2021 @03:11PM (#27666365)
Yes, this exactly. Use timezones when displaying something to a user and otherwise not at all, imho.
Re:Temporal: Getting started with JavaScript's new date time... by nicoburns on Monday June 28, 2021 @06:26PM (#27669073)
This falls down if the timezones themselves change. e.g. if DST was planned, but was then cancelled. You really want to store the original time with timezone as well as UTC.
Re:Temporal: Getting started with JavaScript's new date time... by chrisweekly on Monday June 28, 2021 @02:08PM (#27665373)
Tangent: moment.js has been replaced by date-fns (and dayjs) as the modern alt to native Date().
Re:Temporal: Getting started with JavaScript's new date time... by gui77aume on Monday June 28, 2021 @08:50PM (#27670297)
I had better luck with date-fns than with moment.js, from Chile perspective, better daylight saving time handling.