▲ | kaoD 5 days ago | ||||||||||||||||||||||||||||||||||||||||||||||||||||
I like how Temporal[0] does this. What you were dealing with is Temporal.PlainDate[1], i.e. a date with a calendar associated but no time or timezone (might be due to being implied but also might be irrelevant, like in birthdates). Temporal has other cool types, each with distinct semantics: - Instant: a fixed point in time with no calendar or location. Think e.g. "the user logged in at X date and time" but valid across the world for any timezone or calendar system. This is what we usually use "Unix UTC timestamps" for. - ZonedDateTime: like an Instant but associated with a particular calendar and location. Think an Instant but rendered "real" into a calendar system and timezone so the user can see a meaningful time for them. - PlainDate: already discussed. Think e.g. birthdates. - PlainTime: think "run task every day at 6:30pm". - PlainDateTime: like an Instant but associated with a calendar system, but no timezone. Think e.g. what a user would insert in a datetime picker, where the timezone is implied instead of explicitly selected. - PlainYearMonth: think e.g. "we'll run our reports during October 2025". - PlainMonthDay: think e.g. "my birthday is June 13". - Duration: think e.g. "the task ran for 3hrs 30min". Also see its important concepts[2]. [0] https://tc39.es/proposal-temporal/docs/ [1] https://tc39.es/proposal-temporal/docs/#Temporal-PlainDate | |||||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | Terr_ 4 days ago | parent | next [-] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
I hope that as time goes on software design get better about modeling things that are guesses, conjecture, etc. rather than Absolute Facts. As-is, we assume lots of things are facts and we just hope it's true enough to avoid problems. (Starting with the business requirements. :p ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | keeganpoppen 5 days ago | parent | prev | next [-] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
yeah, it was a long (and painful) time coming, but i think the temporal api finally basically nailed it. you know a library is good when you learn something about how to think about the problem just from how the code/api is structured. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | geocar 4 days ago | parent | prev [-] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
> a date with a calendar associated but no time or timezone (might be due to being implied but also might be irrelevant, like in birthdates). It might also be relevant: Ever ask an older Korean person their age? > Instant: a fixed point in time with no calendar or location. Think e.g. "the user logged in at X date and time" but valid across the world for any timezone or calendar system. This is what we usually use "Unix UTC timestamps" for. This is not a thing. Those are intervals to some Epoch, maybe taking into account leap-seconds and maybe not. They are not very useful except grossly over long ranges. > - ZonedDateTime: like an Instant but associated with a particular calendar and location. Think an Instant but rendered "real" into a calendar system and timezone so the user can see a meaningful time for them. Like when a user logged in at X date and time. They don't do this from no location, but from some location. > - PlainDate: already discussed. Think e.g. birthdates. And already wrong. > - PlainTime: think "run task every day at 6:30pm". Erm no. You can say 18:30 hours after midnight, or you can say when the calendar says 6:30pm, but these are different things. Imagine the poor fool who wants to run the task every day at "1:30am" and has it run twice on some days. Bars close in some parts of the world at 30h (30時) to mean 6am the following day. > - PlainDateTime: like an Instant but associated with a calendar system, but no timezone. Think e.g. what a user would insert in a datetime picker, where the timezone is implied instead of explicitly selected. No, like a string. > - PlainYearMonth: think e.g. "we'll run our reports during October 2025". Nonsense. Also a string. > - PlainMonthDay: think e.g. "my birthday is June 13". Your birthday might be on the 29th of January. You cannot do reasonable arithmetic with such things, so it might as well be a string like many of these others. > I like how Temporal[0] does this. I don't if you can't tell. This stuff is complicated and I'd like more people exploring it because I don't know The Right Answer™ either, but I know enough to know that every existing solution is wrong in some way that can cause real harm. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|