As someone working working on time sensitive code on embedded systems (DVRs that get UTC from the broadcast), I can certainly agree with the issues laid out in the post. As an example: We have some certifications our product must pass and the certification body plays a 4 minute looping broadcast stream with the test condition in it. It turns out I handled the time jump hat occurred when the stream would loop around p…
just to add to the examples here: last week i was writing code to handle calibration data from seismic detectors. these are connected to GPS receivers and so have pretty accurate times. yet when i triggered a calibration it would start 1 minute in the past. somehow the receiver was moving back in time before starting the calibration.... ...or ntpd on the test computer had failed and the machine was a minute fast :o)…
What every programmer should know about time
71–80 of 133 posts
Re: What every programmer should know about time
#72I want to correct this common misconception that UTC is enough. Calendar time with all human traditions involved is more complex than a simple timestamp.
The advice above is incorrect for calendar and scheduling apps, or anything that has a concept of a repeating event.
An example: we have a weekly meeting occurring 9AM Monday in San Francisco. You are in London and want to attent the meeting over Skype. When is it in London time?
It depends.
On 7 Mar 2011 it's at 5pm
On 14 Mar 2011 it's at 6pm
On 29 Mar 2011 it's at 5pm
To make these calculations, you need to know timezone & daylight saving time (DST) rules of both your current location and the home location of the event.
A "DST zone" of a home location of a repeating event has to be saved together with a time and thus it's not just presentation-layer issue.
Re: What every programmer should know about time
#73"The system clock can, and will, jump backwards and forwards in time due to things outside of your control. Your program should be designed to survive this." This is one of my favorite go-to test cases. I've found some really fantastically interesting, catastrophic network halting badness with this really simple test.
My first thought was that this was some kind of prank :-) but seems it was a hardware issue on the parent machine combined with ntpd trying to compensate.
Re: What every programmer should know about time
#74Re: What every programmer should know about time
#75Also it doesn't take different calendars into account, still doesn't work with leap seconds, doesn't deal well with time spans (t1 - t2 specified in seconds can be a lot things in reality), ...
Use a proper date time library to deal with dates and store them in your database in a string format, including the time zone. It depends on your application which time zone (UTC or local), but in general UTC is best, and the local time zone could be a second column if you need the info (or it could be a property of the user, but e.g. many calendaring application then screw it up in the UI layer...)
I'd like to read a book on the UI issues associated with dates and times, anyone know of something like that?
Re: What every programmer should know about time
#76> Timezones are a presentation-layer problem! I want to correct this common misconception that UTC is enough. Calendar time with all human traditions involved is more complex than a simple timestamp. The advice above is incorrect for calendar and scheduling apps, or anything that has a concept of a repeating event. An example: we have a weekly meeting occurring 9AM Monday in San Francisco. You are in London and want…
Re: What every programmer should know about time
#77> Timezones are a presentation-layer problem! I want to correct this common misconception that UTC is enough. Calendar time with all human traditions involved is more complex than a simple timestamp. The advice above is incorrect for calendar and scheduling apps, or anything that has a concept of a repeating event. An example: we have a weekly meeting occurring 9AM Monday in San Francisco. You are in London and want…
If you save the UTC date of the event, the localized date for some timezone can be extrapolated from it.
Re: What every programmer should know about time
#78> Timezones are a presentation-layer problem! I want to correct this common misconception that UTC is enough. Calendar time with all human traditions involved is more complex than a simple timestamp. The advice above is incorrect for calendar and scheduling apps, or anything that has a concept of a repeating event. An example: we have a weekly meeting occurring 9AM Monday in San Francisco. You are in London and want…
Storing a recurring class of dates is - of course - more complicated; but then has anyone ever suggested otherwise?
Re: What every programmer should know about time
#79> Timezones are a presentation-layer problem! I want to correct this common misconception that UTC is enough. Calendar time with all human traditions involved is more complex than a simple timestamp. The advice above is incorrect for calendar and scheduling apps, or anything that has a concept of a repeating event. An example: we have a weekly meeting occurring 9AM Monday in San Francisco. You are in London and want…
There is no need to save the home location with the time. If you save the UTC date of the event, the localized date for some timezone can be extrapolated from it.
I just wanted to highlight that "time" is a human concept that in informal setting means a lot of things, but when you start to model it formally, it can be more complex than a single timestamp.