Skip to main content

How to count to one

Dealing with dates and times is one of the hardest problems in software development. It might seem simple at first. There are just 6 basic variables you need to worry about: seconds, minutes, hours, days, months and years. With the time components it stays that easy. They are (almost) always composed of the same amount of their smaller counterparts. Minute is 60 seconds, hour 60 minutes and even day is usually 24 hours. It's mostly the months that is the first sign of something funky. There are months with three different lengths, one of them even dependant on the year.

With all these leap years or seconds with variable length months it's still easy. It's all logical and taken care of every basic datetime library ever implemented. Things only start to get interesting when you need to deal with location as well. The time isn't same everywhere (and I'm not even going to talk about this in relativistic sense). The world is divided in 38 different timezones. So depending on your location on earth the local time is different. Easy still when you are mostly staying within that same timezone. Just need to adjust the time according to the local offset.

But people like to travel (or at least used to, when it was still possible). And while doing so they like to keep up with the time, adjust to local time while keeping themselves aligned with their home time. Oh, and before I forget: daylight saving times.

So just keeping up what time is it while freely moving around is already a bit of a challenge imagine what it is to try to make sense of all this when dealing with the intervals, like say a daily streak.