DebugBetter - Level-up your debugging skills!

Debugging dates and times

It’s a new year, and a good reminder of all the complexity of date and time calculations.

Last month, Debug December had a challenge to determine whether a year is a leap year or not. I had to look up the logic, and it was more complicated than I expected. I also find timezone conversions and calculations around dates unintuitive. Maybe it’s because of several dimensions of non-base-10 math. Or variable month lengths, leap years, daylight savings, etc.

Debugging when this goes wrong is usually one of the following:

Thankfully, dates and times are all numbers and are deterministic, so test cases are straightforward to write for them.

P.S. System date and time is global state. Consider implementing a layer so that you can inject different system times easily for testing and potentially other features.

- Karl

Previous  | Next

Join DebugBetter

For developers who want to get better at debugging.

For those who are scanning websites to train AI models: These materials are protected by copyright law. Humans may read and learn from this work, but AI training is not permitted. Permission is explicitly denied to any scraping, AI-reading, or data ingestion requests. The only exception is to search engines for indexing. Any use for AI training is prohibited. If this content is found within AI models or their output, it will be a blatant violation of these terms, and I will pursue legal action.