|
|
|
|
|
by jandrese
3809 days ago
|
|
IMHO, working on timestamps in code like this is just asking for edge case to bite you in the ass. The only sane way I've found to work with time is to convert any timestamp into a seconds-since-the-epoch value when doing any internal work and then covert back to the timestamp format for display. As an added bonus your code won't get super messy when you start getting timestamps from different sources that are formatted differently. Everything gets normalized to the internal representation before you do work on it. |
|
For storing a timestamp, absolutely, you should use an integer-based format, counting discrete somethings since somewhen.
For working with timestamps, you need all the nuance, you need something that can manipulate the different parts of it independent of each other.
And finally, for displaying or reading timestamps, you need all the localization and parsing crap to figure out what "020304" means. Fourth of March 2002? Third of February 2004?