In my programmer's life I frequently deal with all kinds of timestamps. As the code is relatively, ahem, "mature" those timestamps come from all kinds of sources. There are 64-bit ticks (GetTickCount64), multimedia time (timeGetTime), performance counters (QueryPerformanceCounter), performance counters in disguise (TStopwatch), and there is also a TDateTime (NowUTC) mixed in from time to time.
All this mess would not be that bad had the timestamps been only used locally. If you sample a timestamp and then a few lines later check whether so-and-so time has expired, all is well. You will always know what the source of the timestamp was and what to compare it to.
Problems occur when the timestamps are grabbed on one side of the system and consumed on the other side. Let's say that the code receives a block of data over some internal communication mechanism. A part of that data is a timestamp representing a creation time of that data block. You have to check how much time has elapsed since then. How do you do that?
Well, firstly you have to know in what units this timestamp is stored. Is it a floating point number (TDateTime) or a 64-bit integer? In the latter case, does it store a number of milliseconds, 'ticks' (whatever that is) or something else?
Secondly, you have to get "current timestamp" from the correct time source so you can do the calculation. So you have to know what the source was. And if you're not sure, you'll have to dig through the code to find the point where the original timestamp was created.
The former problem is somewhat solvable by using descriptive variable/field names. For example, if a variable stores a timestamp in milliseconds, I always use a suffix _ms. In the example above I would use a field DataCreationTime_ms or something similar.
The latter problem, however, is hard. You could use suffixes (DataCreationTime_Tick64_ms) but that gets ugly pretty fast. You could also document the time source (and you should!) but that again stops you when you just want to write some code.
Even worse, both solutions only work if you take care when coding. Delphi won't stop you from subtracting TStopwatch.GetTimeStamp from a value that is storing a result of timeGetTime, although the result won't make much sense.
Clearly, I needed something better, so I wrote* the GpTimestamp unit which tries to solve this mess. There is also documentation and unit tests, if you want to jump in now.
(* When I say "I" I actually mean Claude. I was just an idea-man on this project. I'll say more about that in the following post...)