News for hackers. Stuff that matters.
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.