Email from a colleague claiming my "clock/time-of-day" software is broken.
As "proof", he offered up his (manual!) calculations and how they differed from results my code generates.
This, of course, because he has an incomplete understanding of "time". :< Or, has "forgotten" certain details in favor of a simpler mental model.
This all stems from the fact that we tend to do "time arithmetic" in our heads and gloss over idiosyncrasies that we (likely!) know about.
"This date next year is exactly one year from now." "This date next month is exactly 1 month from now." "This day-of-week NEXT week is exactly one week from now." "This time tomorrow is exactly 24 hours from now." "This 'minute' next hour is exactly one hour from now."
Nope.
These are only true if we use "squishy" definitions of time intervals.
If you're a person looking at a timepiece, such approximations may be acceptable. But, if you are an algorithm doing things at a certain *rate*, then you expect time to be incredibly uniform.
I think I can eliminate (most?) of these screwups by NOT allowing "human time" to be mapped to "system time" (a monotonically increasing counter that operates at a constant rate). So, instead of arranging for something to happen "an hour from now" by "incrementing the current hour" and using that as a scheduling criteria, take the current
*system* time and add 60 min * 60 sec to it and use that as the deadline.
Note that the "human time" corresponding to that could be confusing: 1:25:00 + 1 hour = 3:25:00 1:05:36 + 1 hour = 1:05:36 23:51:00 + 1 hour = 0:50:59 But, that only is confusing it *humans* want to read it. The machine (i.e., your algorithm) never is encumbered with such idiocy!
I think "non-programmers" might have a problem with this as they likely think "add 1 to the hour" to get a time one hour from now. But, I think they can learn to deal with it as: now = clock.now() alarm.set(now+HOUR)
So, as long as I don't let you map human time back to system time, you aren't likely to make mistakes with "time arithmetic".
But, that smells like it would cause other cognition problems...