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…
Falsehoods Programmers believe about Time
161–170 of 222 posts
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?
Re: Falsehoods Programmers believe about Time
#163About #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 .
Re: Falsehoods Programmers believe about Time
#164This 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…
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
#16539. The next day after 3 Sep 1752 is 4 Sep 1752.
Re: Falsehoods Programmers believe about Time
#166N+?? 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…
You know that's not unix time, right? Unix time doesn't include leap seconds.
Re: Falsehoods Programmers believe about Time
#167Re: Falsehoods Programmers believe about Time
#1681. 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
#169Some 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 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
#170How 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…