Live data from Hacker News

Falsehoods programmers believe about time

infiniteundo.com

101–110 of 212 posts

Re: Falsehoods programmers believe about time

#101
post #80
post #73

Earlier quoted context omitted.

I hereby announce my campaign for the role of Time Druid.

Your symbols of office shall be a blinking 12:00 and the date 01-01-1970. Wait. In fact, if you weren't born on 01-01-1970, you can't be Time Druid. Sorry.

Do you mean 01-01-1970 or 01-01-1970?

Re: Falsehoods programmers believe about time

#102

The biggest falsehood a programmer could believe about time is that they have the ability to roll their own time manager. Just use a battle-hardened library and hope for the best. Dealing with time in code is crazy-making in a way I never expected.

I personally have not had much experience with it.

Would love to hear some horror stories you've encountered. It might help me keep an eye out for it.

Re: Falsehoods programmers believe about time

#103

One of the hardest programs you could ever have to write would be historical times taking into account all the time zone and Daylight Savings Time changes over the years. It might be impossible. Just look at Indiana's history with time zones and DST.

Many years ago, a user filed a bug report that the timezone information we used for historical places in Indiana was incorrect. I don't remember exactly what the user was doing, but I think it had something to do with train schedules or something.

I did not fix that bug. (But I did learn that the 'TZ' database has this information, though I think 'America/Indiana/*' had been pruned out of the copy our JVM was using.)

Re: Falsehoods programmers believe about time

#104
The "opportunity for bugs" I didn't realize until I was over 10 years into my professional career:

10 AM

11 AM

12 PM 01 PM 02 PM

03 PM

I see large software systems for things like airlines and trains sometimes make this mistake, for instance a 1 hour trip on a ticket that says "11:30AM - 12:30AM" which is actually negative 11 hours.

I have a collection of photos somewhere of every time I've caught it. If I could change anything about time that probably nobody would care about, it would be to align those two cycles.

The fact that I catch it every couple months on widely deployed systems I interpret as the signal that basically nobody notices/cares about it as everyone knows a -11 hour train ride isn't how time works.

Re: Falsehoods programmers believe about time

#105
The proposed moral of this story, and those like it, is to avoid re-implementing general-purpose libraries.

Yes, good. But not all applications need a “platonic ideal” understanding of time. Often when you type just the code you need, the system performs excellently, and the code is minimal.

Re: Falsehoods programmers believe about time

#106

We should just define a year to be 360 days long and made up of 12 30 day months. Then we can elect some druids or whatever to arbitrarily, at the start of each year, define which dates the seasonal borders will land on. Events which are truly dependent on weather can be defined in terms of "Days after the season starts." Or we could define a 5.5+-.5 day holiday between the beginning and end of a given year. Those da…

https://qntm.org/calendar See also: https://qntm.org/continuous and https://qntm.org/abolish

Hmm the only one which seems to apply is:

> having one or two days per year which are part of no month is stupid

which I've cleverly circumvented by adding almost a while week. I believe in this case the stupidity overflows and it becomes a good plan again.

Re: Falsehoods programmers believe about time

#107

The biggest falsehood a programmer could believe about time is that they have the ability to roll their own time manager. Just use a battle-hardened library and hope for the best. Dealing with time in code is crazy-making in a way I never expected.

I agree. I'd wager most programmers don't need to actually worry about calendars, but most occasionally need to worry about time. Just use a library and read the docs for what to expect to happen when you do something like getCurrentTime. What is the resolution, does it monotonically increase, etc.

If you actually need to worry about calendars and user input, you have my sympathy.

Re: Falsehoods programmers believe about time

#108
Python specific:

- `pytz.timezone(timezone_name)` will give you the current offset for that timezone - well, it will at least be some consistent offset - surely, every timezone has the same reference starting point?

What `pytz.timezone(name)` actually does is initialize a timezone object at the point in time of the first entry in the tz database for that zone. For example, New York had an offset of 4:56:02 prior to 1883 November 18, 12:03:58 [1]. That is the "starting point" for America/New_York and US/Eastern (which I think is an alias of New_York before a certain date). Which is why you get

    >>> pytz.timezone('America/New_York')
     
Ish. Not sure where those 2 seconds went. But that explains why you see that strange 19:04 (-3:56) offset. The real way to use it is

    >>> pytz.timezone('America/New_York').localize(your_specific_datetime)
Timezones without a reference time are deceptive.

[1] https://en.wikipedia.org/wiki/Tz_database#Example_zone_and_r...

Re: Falsehoods programmers believe about time

#109

Earlier quoted context omitted.

Something very similar already exists (in theory): https://en.wikipedia.org/wiki/International_Fixed_Calendar Kodak used to run on this calendar.

I was going to mention this. 13 months each with 28 days.

Lousy Smarch weather (doh!)

Re: Falsehoods programmers believe about time

#110
post #42

>Leap years occur every 4 years. Isn't leap year calculation one of the very first things you do in most programming tutorials/schools? I know that a lot of people don't know this, but most programmers should, r-r-r-right?

If you handle dates and times yourself on that level, prepare to be in a world of pain. Handling time and dates correctly has a similar difficulty to writing your own cryptographic primitives: If you don't know exactly what you are doing you will shoot yourself (and potentially countless others) into the foot at one in point or another.

Tbh, half of my life I handled them on a financial platform which couldn’t care less of the subj list or standards. It has just ‘wall date’ like yyyy-mm-dd and ‘wall time’ strictly in 00:00:00-23:59:59 range, without a timezone. Two separate types. Never encountered of even heard of any time-related bug there.

I find this simplified date/time very useful, unless you have to manage “continuous and/or real” time somehow. 99% of applications are okay with it, because they’re facing users with exactly the same mental model. Also, albeit not correct scientifically, it reflects many developers’ mental model as well. This is much better than a model that just doesn’t match, which is a world of pain. Someone adds 86400 but it’s the same day, good luck debugging it.

I don’t think this is a cryptographic-level issue.

Post reply on HN