In my experience, the value of time mostly is represented by integer number, by programming languages (C/Java/Golang/Javascript(*)...), and by databases (MySQL, Postgres...), exceptions maybe some GUI/game engines and I always think it is normal. But when I thought more about this topic, I found that maybe it makes more sense to represent time in floating point instead.
Some of my points:
- The value of time is most frequently used in term of continual sequence of events. (eg: is this contract expired yet, is this football match ended yet...). I don't really remember a time when I need to compare 2 time values are equal. So the precision value of integer is not really useful in this case.
- Secondly, when the precision time is needed (let say we need to represent exact time like 01/01/2020 UTC). The 64-bit floating point can represent it just fine. Likes in javascript, where the value is represent by number - 64-bit floating point number of milliseconds from epoch.
- Using 64-bit floating point to store time is actually more space efficient when you need to represent a fraction of unit. Like in golang and C, you need 2 integers (both 64-bit), 1 for number of seconds from epoch, 1 for number of nano seconds.
I can think of some reasons:
- That's how hardware(CPU?) works?
So what do you think is the reason(s)? Thanks.
(*) Javascript don't have native integer type (until recently with BigInt). So the value of date is actually a number, which is 64-bit floating point, but the value is always integer.