This chapter covers
- Thinking carefully about date and time information in specific concepts
- Limiting the scope and documenting precise product requirements
- Choosing the best libraries to use in your date and time code
- Using date and time concepts consistently throughout your code and ensuring date and time code is testable
- Choosing appropriate text formats for date and time data
- Considering corner cases related to calendar arithmetic and time zones
Dates and times occur very naturally in almost all applications, even if it’s only in the timestamp of the application’s log messages. Unfortunately, they often cause significant problems, either with overcomplicated code or bugs that might only be seen for two hours per year or only by users in one remote corner of the planet. It’s all too easy to dismiss such bugs, but with the right set of tools you can avoid them.
- Concepts—Help you think and write clearly about the information you’re working with
- Libraries—Help you turn those concepts into code
Sometimes, the libraries you use will be part of the underlying platform (e.g., using the java.time libraries introduced in Java 8), or they may be third party libraries you need to install explicitly (e.g., the Noda Time library for .NET, to pick an example entirely at random [Well, maybe not quite so random. Jon is the primary author of Noda Time.]).