Live data from Hacker News

Falsehoods Programmers believe about Time

infiniteundo.com

21–30 of 222 posts

Re: Falsehoods Programmers believe about Time

#21
post #15

35. Two timezones that differ, will differ by an integer number of hours.

36. Two timezones that differ will differ by an integer number of half hours.

37. Okay, quarter hours.

38. Okay, seconds, but it will be a consistent difference if we ignore DST.

Re: Falsehoods Programmers believe about Time

#22
post #9

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

The way you're thinking about it, yes -- but the passage of a month may take you from December the [mumbleth] to January the [mumbleth], which are in different years. For some strange reason, code in the wild doesn't always account for that, so the due date for an item may well be eleven months before the request was entered.

Re: Falsehoods Programmers believe about Time

#23
post #10

One of my favorites, encountered in the wild: Your system will never need to handle a time before 1970.

Ran into a similar one about ten years ago; a medical records system with the assumption that you wouldn't need dates before 1/1/1900.

You know who goes to the doctor a lot? Centegenarians.

Re: Falsehoods Programmers believe about Time

#24
post #20

35. There are years past 2079. SQL Server smalldatetime only goes up to June 6, 2079

Checking the terminal, I don't see any corporate bonds maturing in 2079 yet. But I do see a handful in every year >= 2070 and <= 2077. So maybe a few more years and some people / firms will start hitting bugs...

Re: Falsehoods Programmers believe about Time

#25
post #8

Who believes these things? February is always 28 days long? Any 24-hour period will always begin and end in the same day (or week, or month)? A week always begins and ends in the same month?

Perhaps the accurate title is "Assumptions programmers make about time"

Re: Falsehoods Programmers believe about Time

#26
post #11
post #8

Who believes these things? February is always 28 days long? Any 24-hour period will always begin and end in the same day (or week, or month)? A week always begins and ends in the same month?

He's talking about test code. So if those test cases are missing, but the programmer thinks the tests are thorough, then it looks like the programmer believes those things (or forgot that they weren't true).

A bad test might boil down to,

    assert(month(now()) == month(now() + 24.hours))
then fail from time to time.

Re: Falsehoods Programmers believe about Time

#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.

Re: Falsehoods Programmers believe about Time

#29
post #15

35. Two timezones that differ, will differ by an integer number of hours.

36. Two timezones that differ will differ by an integer number of half hours. 37. Okay, quarter hours. 38. Okay, seconds, but it will be a consistent difference if we ignore DST.

39. If you create two date objects right beside each other, they'll represent the same time. (a fantastic Heisenbug generator)

40. You can wait for the clock to reach exactly HH:MM:SS by sampling once a second.

Re: Falsehoods Programmers believe about Time

#30
post #18

If you really want to stress test time handling code, try to get it to accept Feburary 29, 1900 and Feburary 29, 2000. The first doesn't exist but the second does. But really, with regards to time use whatever library came with you programming language.

That will stress it a bit, but to really torture it, see if it accepts 2012 June 30 23:59:60
Post reply on HN