Over the years I have come across different interpretations of the end of a day. But what is the correct way of representing it when comparing dates and intervals?
I have found that some people seem to prefer 23:59:59, while others do use 00:00:00.
Here on StackOverflow I have even found a few instances of questions relating to the use and display of 24:00:00, however the scope of this question is more focused on determining how to split two days.
In other words we are interested in the problem of determining where does exactly a day ends, and where the next begins. This seem to be a common problem in many applications that require even the most basic time intervals comparisons or calculations.
To clarify the above interpretations, below are three examples representing January 1st 2014 under the three different interpretations:
- Quasi midnight:
2014-01-01 00:00:00 - 2014-01-01 23:59:59
- Midnight sharp:
2014-01-01 00:00:00 - 2014-01-02 00:00:00
- Military midnight:
2014-01-01 00:00:00 - 2014-01-01 24:00:00
While I do feel that the quasi midnight interpretation is the most intuitive one, it also seem to requires a fair amount of boilerplate to point the time correctly. Additionally there's the risk of running into edge cases when that last second of the day isn't correctly handled, or the risk of influencing performance when scanning huge collections of intervals for testing around those gaps.
Similarly, the military midnight interpretation also seem to require some boilerplate to setup the dual representation of that division point. Without too much thinking I can't think of many complications using this approach.
Finally the midnight sharp interpretation seems to be good candidate for the the most consistent one. Unlike midnight quasi, it does not require boilerplate to set the time and it naturally behaves with the operators <
, <=
, >
and >=
.
It's worth noting that the PHP language already interprets 2014-01-01 24:00:00
as 2014-01-02 00:00:00
, which has the effect of converting the date to midnight sharp interpretation.
Are there notable precedents in exemplary FLOSS libraries or standards that would justify use of one interpretation over another?
time
types found in most platforms is impossible. For example you never consider the timezone, without which you don't really know what time it is (imagine summer time changes). There are libraries like Joda Time in Java or Noda Time in .NET that make such matters explicit, so that End-Of-Time for onedate
can never be confused with start of time for the next, timezones are always explicit, etc – Transmigrate