| Almost all the edge cases with time have to do with localization. Build your time library on (un)signed 64 bit integers representing the number of nanoseconds since the utc epoch. Adjust above sentence to reflect the level of precision and range your use case needs. You are now done for 80% of use cases (perf timing, logging, timeouts, event storage, event ordering within jitter). If you need to parse/display for humans or have something happen at a particular time in a particular timezone, things get gross. But that's no different than any other situation where you eventually have to interface machine data with humans. Either it's your particular expertise or it's a distraction and you should use someone else's solution. |
You poor sweet summer child. Has no one told you about the leap seconds yet? Unix time is not the number of seconds since epoch. It deliberately excludes leap seconds, which happen unpredictably whenever scientists measure the Earth as having spun at a different enough speed for long enough.
Time is fucked on every level:
- Philosophical: What is time? We just don't know.
- Physical: Turns out there is no such thing as simultaneity, and time flows differently at different locations. Time may be discrete at the Planck level, but we don't really know yet.
- Cosmological: The Earth does not rotate at a constant speed, the Earth does not orbit the Sun at a fractional component of its rotation, and the Moon does not orbit at even ratio either.
- Historical: Humans have not used time or calendars consistently.
- Notational: Some time notations are ambiguous (e.g. during daylight savings transitions) and others are skipped.
- Regional: Different regions use subtly different clocks and calendars.
- Political: Different political actors choose to change time whenever they feel like it with little or no warning.
- Religious: Many religions come with their own system for timekeeping, and people don't like when outsiders impose other systems.