Live data from Hacker News

Falsehoods Programmers believe about Time

infiniteundo.com

161–170 of 222 posts

Re: Falsehoods Programmers believe about Time

#161
post #126
post #74

This sort of stuff is why I scream "NNNNOOOOOOOOOOOOOO!!!!!!" when people store date/time as integers (i.e. "unix timestamps") when almost every database and programming language has a proper date or datetime data type, and a boatload of library functions that correctly compute differences between dates, handle leap years and time zones, etc. Well maybe not always correctly, but it's more likely that YOU will screw u…

IMHO you will change your tune with more time and experience; numerics are often more portable and unambiguous than string or serialized-object alternatives... e.g., if you pass around datetimes as "int64 count of 100-ns intervals since 1-1-1601 UTC" there is little opportunity for someone who doesn't know how to use it to get a quasi-usable yet incorrect datetime out of it. Also note, there are plenty of database sy…

There's a standard for that. ISO 8601. Use that. Don't make up your own.

Re: Falsehoods Programmers believe about Time

#162

"7. 7.A week (or a month) always begins and ends in the same year." Not sure what the (or a month) is doing there. I'm pretty sure the end of december is the end of the year and the beginning of January is the beginning of the year. A month can't span multiple years...can it?

Years start on Sept. 11th in Ethiopia http://en.wikipedia.org/wiki/Ethiopian_calendar

Re: Falsehoods Programmers believe about Time

#163
post #27
post #9

About #7: doesn't a month always end in the same year it started?

Between 1582 and 1752 England had two different New Year's Days, January 1 and March 25, used for different purposes. The same day had different years depending on who you were talking to. See http://en.wikipedia.org/wiki/Dual_dating .

The tax year in UK still start/end on March 25th IIRC

Re: Falsehoods Programmers believe about Time

#164
post #83

This is why I really like logical clocks: by abandoning the primitive and outdated concept of "time" altogether, they allow you to deal reliably with causality, which is often all you're really interested in. http://en.wikipedia.org/wiki/Lamport_timestamps http://en.wikipedia.org/wiki/Vector_clocks That said, UTC timestamps since the epoch are one of the more straightforward ways of dealing with time, if you must sul…

UTC timestamps since the epoch

Since we add leapseconds, and UTC includes those leap seconds, it's hard to know "time since the epoch". For example, unix/posix time is not the number of seconds since the epoch.

Re: Falsehoods Programmers believe about Time

#166
post #129
post #63

N+?? The time library in your programming language is correct. Every time library I've ever dealt with will have serious problems with at least one issue listed on the original article or in the comments here. JodaTime (on the JVM) is by far the best, but even they have problems, and are creating a new library to solve those.

I think that for the vast majority of real-world software applications JodaTime is bloated and unnecessary. Most applications need only three 'classes' to represent time: 1. A timestamp (ie. number of milliseconds since midnight on 1 January 1970 GMT) 2. A Gregorian Date (ie. three numbers representing day, month, year) 3. A TimeZone (to convert between 1 and 2) In Java the first and third types are perfectly represe…

1. A timestamp (ie. number of milliseconds since midnight on 1 January 1970 GMT)

You know that's not unix time, right? Unix time doesn't include leap seconds.

Re: Falsehoods Programmers believe about Time

#167
post #153

Earlier quoted context omitted.

UTC time does not go backwards. Leap seconds are implemented as a minute with 61 seconds.

It can also, theoretically be a minute with 59 seconds, though I don't believe this has ever happened.

True, but that still is not going backwards.

Re: Falsehoods Programmers believe about Time

#168
How about some calendaring issues I'm sure any Israeli is familiar with:

1. Weeks start on Monday.

2. Days begin in the morning.

3. Re: 2, holidays span an integer number of whole days.

Explanations:

1: In Israel, the week starts on Sunday. Most programs have support for changing the "start of week day". Most programs.

2-3: In the Jewish calendar, the day starts when the moon comes out. This means that holidays that most calendars write as "Wednesday" will actually start on Tuesday night, and last until Wednesday night.

Re: Falsehoods Programmers believe about Time

#169
post #150

Some more falsehoods: 1. Time never goes backwards (as other people have pointed out, time zones break this). 2. UTC time never goes backwards (as other people have pointed out, leap seconds break this). 3. The system boot time never changes. On most platforms, the current time is defined as "boot time plus uptime", and setting the current time is performed by changing the boot time. 4. System uptime never goes backw…

> 5. POSIX's CLOCK_MONOTONIC never goes backwards. On some platforms and virtualization environments this can break with CPUs shared between virtual machines. > 6. On systems without virtualization, CLOCK_MONOTONIC never goes backwards. On some platforms this can occur due to clock skew between CPUs. Could you explain these situations in more detail? Or cite a source I can take a look at? CLOCK_MONOTONIC is what I us…

If CLOCK_MONOTONIC goes backwards your platform's implementation is broken. As defined in POSIX it does not ever go backwards. It counts the time since an unspecified point in the past that never varies after system start-up.

If your process is rescheduled to a different CPU, it must still go forwards regardless of TSC variance between the CPUs.

Of course if your uptime hits 68 years or so, the clock will wrap. If your app can't have any downtime in 68 years though I hope you've got the budget to think about this sort of thing :)

Re: Falsehoods Programmers believe about Time

#170
post #168

How about some calendaring issues I'm sure any Israeli is familiar with: 1. Weeks start on Monday. 2. Days begin in the morning. 3. Re: 2, holidays span an integer number of whole days. Explanations: 1: In Israel, the week starts on Sunday. Most programs have support for changing the "start of week day". Most programs. 2-3: In the Jewish calendar, the day starts when the moon comes out. This means that holidays that…

Or anyone living in the Arab Middle East where: 1. Weeks start on a Sunday 2. Friday and Saturday are the weekend, except where it's Thursday and Friday 3. Some countries have changed their weekends in the last 10 years to Fri/Sat to make doing business internationally easier 4. Not everyone has a two-day weekend 5. Religious holidays depend on moon sightings and cannot be precisely predicted ahead of time
Post reply on HN