Weird DST Issue

Question: When is 7 days ago not 168 hours ago?

Answer: When DST changes during the 7 days, in which case it's either 167 (in the spring) or 169 (in the fall) hours ago.

I've got some graphs that display the current day and a seven days in the past, but the x axis is actually built based on hours (e.g. today's midnight is hour zero, yesterday's noon is hour -12, etc).  I'd done the queries to just extract data from seven days before midnight on, and wondered why my graphs were all screwy this week.  After quite a search, I realized that I was getting seven days, but seven days didn't equal 168 hours, and that the DST change was the reason.

In this specific case, the assumption was actually that every day was exactly 24 hours long, and while that holds true the majority of the time, it's an incorrect statement two days per year.  So watch out.

I'm not really sure what the general solution is if you need to assume a day is of a certain length.  In my case, I just changed the queries to be hour based, so seven days before midnight today is actually being extracted as one AM on 10/24.  Not ideal, obviously, but in my case having exactly 168 hours was more important than 168 hours ago being a midnight.  I suppose the right solution would to have sunday's section of the graph be 1/24th larger than the other days to accoun for the extra hour, and actually display 169 hours.  But the charting engine won't handle that.

Comments are closed.