Live data from Hacker News

What every programmer should know about time

unix4lyfe.org

131–133 of 133 posts

Re: What every programmer should know about time

#132

Earlier quoted context omitted.

The article should add a caveat: use UNIX time when you are recording the current time to store for later use. That can always be formatted in the user's current timezone to display back. When you're inventing a rule system based on local times, as you are above, of course you need to track the rules in the local time zone. That's because the rule is: "do this thing at 9am in my particular local time zone", not "do t…

And that doesn't even get into the problem of the DST dates changing at the whim of legislation like it did recently in the US about 5 years ago. If you are attempting to track timezone instead of UTC you've now have to check date ranges when different DST was in effect. Very messy stuff. Better to just keep it in UTC or Unix if you need the offset it was recorded in as you mentioned.

Yes to everything stated above. We have a system that schedules events in the future, and the times are all wrong for a couple hours per year because the system is effecting DST @ 12:00am UTC instead of 2:00am local time! Getting time right in all cases is much more challenging than my people realize.

Re: What every programmer should know about time

#133
Other little know facts about time:

The first day of the week can be sunday or monday depending on where you are.

The way to count the weeks isn't the same everywhere.

Some advice:

Default to using ISO 8601 whenever possible http://en.wikipedia.org/wiki/ISO_8601

Don't ask for more precision then you actually need (Don't ask date & time when you only need year & week)

Don't store dates and times with more precision then was actually entered (e.g. Don't ask for year & week, and then store the (calculated) first day of the week.

On my first large project I made the mistake of asking for the year & week while storing the calculated first day of the week, however using the wrong first day of the week and the wrong numbering of weeks…

Post reply on HN