Live data from Hacker News

Never write your own date parsing library

zachleat.com

81–90 of 333 posts

Re: Never write your own date parsing library

#81
post #31

Earlier quoted context omitted.

Those ISO-8601 dates are great for date processing with primitive tools such as GNU sort or awk since they sort lexically, at least if you're not comparing dates in different time zones.

ISO 8601 is the way .

Yes, except for all the completely unhinged stuff in ISO 8601. You probably do not want to deal with durations, or repeating intervals, or even week dates and ordinal dates.

Re: Never write your own date parsing library

#82
post #36

Earlier quoted context omitted.

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 acr…

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.

Relatedly, std::chrono isnt exactly a beauty, but it did get people thinking about time points and durations and clocks and which operations are valid ways to move among them. Stuff like this is good.

Re: Never write your own date parsing library

#83

No other programming concept has caused me more grief than dealing with time and timezones. It starts to get really mind-bendingly complex once you start thinking about it deeply. That is even before you start encountering the quirks (some places have timezone changes that depend not only on the time of year but also on the actual year). Lesson learnt - choose a library (moment is great) and never think about time ag…

It’s because it is not systematic historically. It’s a system full of edge cases

Re: Never write your own date parsing library

#84
post #12

It's like that joke someone posted on Twitter: "I was in favor of space exploration until I realized what it would mean for date/time libraries"

It's funny to reason why we must go to bed when the clock has a certain number, since modern technology could easily be programmed to adjust as needed. No technical reasons the Martians can't go to bed at 9:00am today and 9:40am tomorrow. This mirrors my thoughts on why farmers caring about daylight savings time is farcical, farmers I know use the timekeeping of "crack of dawn" and "sunset".

We're mostly still a diurnal species. We go to bed at 9PM instead of 9Am for evolutionary reasons. We can fight against it, but the reasons are as arbitrary as biology is.

Likewise Daylight savings is a concept that had its uses, but makes less sense as technology progresses. I don't think even farmers care much about 7AM approximating to sunrise and 6PM as sunset.

Re: Never write your own date parsing library

#85

Earlier quoted context omitted.

A second is still originally defined as 1/86400 of an Earth day. That doesn't make it unusable as a cross galactic time unit, and I think the same goes for years and hours.

Seconds are now (in SI) defined as calculated from behavior of cesium-133 atoms. https://en.wikipedia.org/wiki/Caesium_standard

You can also define "days" and "years" in terms of that SI definition.

I don't think that helps with the original concern.

Re: Never write your own date parsing library

#86

Multiple times in my career I've had a good laugh when a non-technical manager says something along the lines of "it's just the date, how hard can it be?"

Add phone numbers, email addresses and human names to the list.

Agreed! My team is constantly humbled by the mess of user data: names, birthdays, addresses, people dying or living abroad etc.

Honestly, sometimes I think about the linear algebra, AI, or robotics I learned in school and get this feeling of, "Is this what I'm doing? Stuff that feels like it should be simple?"

It's funny, even our product manager - who is a great guy - can fall into that "come on, this should be easy" mode, and I'll admit I sometimes get lulled into it too. But to his credit, every time I walk him through the actual edge cases, he totally gets it and admits it's easy to forget the on-the-ground complexity when you're in 'planning mode'.

So yeah, seeing your comment is incredibly validating.

Re: Never write your own date parsing library

#87
post #12

It's like that joke someone posted on Twitter: "I was in favor of space exploration until I realized what it would mean for date/time libraries"

It's funny to reason why we must go to bed when the clock has a certain number, since modern technology could easily be programmed to adjust as needed. No technical reasons the Martians can't go to bed at 9:00am today and 9:40am tomorrow. This mirrors my thoughts on why farmers caring about daylight savings time is farcical, farmers I know use the timekeeping of "crack of dawn" and "sunset".

Time zones are less about having uniform names for the times for waking up or going to work or mealtimes, and more about when your calendar changes from one date to the next.

Re: Never write your own date parsing library

#88

No other programming concept has caused me more grief than dealing with time and timezones. It starts to get really mind-bendingly complex once you start thinking about it deeply. That is even before you start encountering the quirks (some places have timezone changes that depend not only on the time of year but also on the actual year). Lesson learnt - choose a library (moment is great) and never think about time ag…

Unfortunately, not many people in our industry really understand the common pitfalls of timezone management, including the people who set the requirements. The classic "I want this to run at 2am each weekday for the user", and then proceed to simply store that as a UTC offset and call it a day (pun intended).

Re: Never write your own date parsing library

#89

Earlier quoted context omitted.

A second is still originally defined as 1/86400 of an Earth day. That doesn't make it unusable as a cross galactic time unit, and I think the same goes for years and hours.

Seconds are now (in SI) defined as calculated from behavior of cesium-133 atoms. https://en.wikipedia.org/wiki/Caesium_standard

9,192,631,770 is clearly a sensible number and not something that's blatantly chosen to match some arbitrary pre-existing geocentric standard like 10,000,000,000 would have been.

Re: Never write your own date parsing library

#90

Earlier quoted context omitted.

Seconds are now (in SI) defined as calculated from behavior of cesium-133 atoms. https://en.wikipedia.org/wiki/Caesium_standard

You can also define "days" and "years" in terms of that SI definition. I don't think that helps with the original concern.

You can, yes. But having it all stem from some fundamental constant value any civilization can handle permits translation between civilizations.

"Our dates start x trillion rotations of pulsar y ago and our unit is defined as z wiggles of cesium" is a starting point.

Post reply on HN