Time, summarized

2025-07-03

These are notes to myself, inspired by/based on Shan Rauf's How to Think About Time in Programming. All errors mine.

A time zone z is a tuple consisting of

On this solid foundation we build the basic concept of the interval between two times, or rather, between two time-formatted strings xz and yz'. The most natural definition is the physical time interval, which in our notation is defined as tUTC(uz'(yz')) - tUTC(uz(xz)). Be advised that this isn't linear, continuous, or necessarily defined on either argument, and its value might change at any time in the future. Due to this last bit of fun, given two time-formatted strings you need to distinguish between the interval between them as an object/concept/spec, and the concrete number in minutes or seconds resulting from evaluating that interval with the functions involved as defined at that moment.

An alternative definition of interval — which often is what users are assuming in one way or another — is the local time interval between two time-formatted strings in the same time zone, i.e. tz(yz) - tz(xz). This, again, isn't necessarily linear, continuous, or necessarily defined on either argument, and its value might change at any time in the future, meaning that it's also important to be aware of the difference between the interval as object/concept/spec and its value when evaluated. It might, but need not, be the same as the physical time interval between the two time-formatted strings.

Finally, we can build comparison operators time-formatted strings — i.e., whether one of them is earlier than another — by looking at the sign of the interval between them. Meaning, of course, that the relative ordering (or even identity) between two time-formatted strings need not be defined or continuous (in the intuitive sense), might differ between local time and absolute physical time, and might vary over time.

Hope this clarifies things!