4 ms·
If we're really talking about timestamps, then by definition they only need to represent the current date and time. It's inherently a more limited use-case than
by evanelias 3y ago
If we're really talking about timestamps, then by definition they only need to represent the current date and time. It's inherently a more limited use-case than general representation of arbitrary dates/times, as timestamps don't require the ability to store dates that occurred prior to the system's existence.
For example, the unix epoch can safely be 1970 because the operating system did not exist prior to 1970, so there's no real-world situation in which you'd be time-stamping a system event or log entry prior to 1970.
That said, time_t is usually a signed type in C. There are several reasonable historical explanations for that though, including the need to use -1 for an error return, and the fact that unsigned ints weren't present in C until 1978.
- zamadatix 3y agoThe danger comes when you need to compare your timestamps to something that may have happened before your system initialized. If you can both guarantee your time type will only ever be used for timestamps on your system and these will never in the future interact with or be compared to timestamps from prior to your system going online then you can get away with an epoch at the start of your system. The Unix epoch was never an issue being 1970 because they knew they were making it as signed, not because they thought Unix systems would never deal with e.g. files from before Unix was created.
- evanelias 3y agoAgain, unsigned ints weren't even present in C until 1978, so of course it was signed -- there was no alternative. As far as I've ever read, negative unix timestamp values generally were not used. Since -1 was used as an error value, you cannot safely determine whether that value represents an error vs a legitimate timestamp one second before the epoch. I'm not familiar with if/how early versions of Unix were able to interact with non-Unix files/filesystems, but I doubt they would preserve metadata such as mtime if so.