this post was submitted on 14 Dec 2023
928 points (99.2% liked)

xkcd

8791 readers
228 users here now

A community for a webcomic of romance, sarcasm, math, and language.

founded 1 year ago
MODERATORS
 

https://xkcd.com/2867

Alt text:

It's not just time zones and leap seconds. SI seconds on Earth are slower because of relativity, so there are time standards for space stuff (TCB, TGC) that use faster SI seconds than UTC/Unix time. T2 - T1 = [God doesn't know and the Devil isn't telling.]

you are viewing a single comment's thread
view the rest of the comments
[–] reverendsteveii@lemm.ee 35 points 11 months ago* (last edited 11 months ago) (4 children)

I just spent two days debugging a reporting endpoint that takes in two MM-YYYY parameters and tries to pull info between the first day of the month for param1 and the last day of the month for param2 and ended up having to set my date boundaries as

LocalDate startDate = new LocalDate(1, param1.getMonth(), param2.getYear()); //pretty straightforward, right?

//bump month by one, account for rollover, set endDate to the first of that month, then subtract one day

int endMonth = param2.month == 12 ? param2.month + 1 : 1;

LocalDate endDate = new LocalDate(1, endMonth, param2.year).minusDays(1);

This is extraordinarily simply for humans to understand intuitively, but to code it requires accounting for a bunch of backward edge/corner case garbage. The answer, of course, is to train humans to think in Unix epoch time.

[–] drislands@lemmy.world 8 points 11 months ago (1 children)

In the example you gave, wouldn't the year be off by one when param2.month is 12?

[–] reverendsteveii@lemm.ee 9 points 11 months ago (1 children)

I was transcribing it from memory and that exact problem cost me like two hours when I was writing it the first time. Well spotted, now write me a unit test for that case.

[–] drislands@lemmy.world 2 points 10 months ago

Y'know, I legitimately said to myself "I bet they were writing that from memory and just forgot the edge case. I wonder if that was a problem when doing it originally?" before I wrote that comment. 😂 Time to get some Spock tests set up!

[–] kogasa@programming.dev 4 points 11 months ago (1 children)

Unix epoch time in UTC, making sure that your local offset and drift are current at the time of conversion to UTC...

[–] reverendsteveii@lemm.ee 2 points 11 months ago (1 children)

i don't even care if its wrong, I just want the code to be readable.

[–] kogasa@programming.dev 2 points 11 months ago (1 children)

You should care if it's wrong.

[–] reverendsteveii@lemm.ee 2 points 11 months ago (1 children)

at the resolution of clock drift in milliseconds when I'm running reports that are, at most, only specific to the day?

[–] kogasa@programming.dev 1 points 11 months ago (1 children)

Clock drift? No. Time zones? Probably.

[–] reverendsteveii@lemm.ee 1 points 11 months ago (1 children)

not really time zones either outside the edge case where a data point exists within delta of midnight so that the time zone drift would result in a date change

[–] kogasa@programming.dev 1 points 11 months ago

Time zones change. Relative times without time zones don't make sense.

[–] Strykker@programming.dev 2 points 11 months ago (1 children)

All dates and times shall be stored and manipulated in Unix time. Only convert to a readable format at the top of the UI, and forget trying to parse user inputs :P that's just impossible

[–] reverendsteveii@lemm.ee 3 points 11 months ago

I picture this being read by the fred armisen "believe it or not, straight to jail" character

[–] chayleaf@lemmy.ml 1 points 10 months ago

Unix epoch time is wrong too, as it doesn't include leap seconds, meaning your time difference will be off by up to 15 seconds.