If you’ve never developed software that deals with dates and time periods, you may assume it’s simple enough. However, the only thing that is simple is making a mistake. For example, in PHP, if you run the method DateTimeInterface::setTimezone, it will perform a timezone conversion from the default timezone. That’s why it’s important to set the timezone in the second argument of the constructor DateTimeInterface::__construct, since in PHP there are so many ways to set the default timezone.
Time period comparison can also be difficult to visualize and get right the first time. For example, using a less than comparison instead of less than or equal to when comparing a date in a MySQL query WHERE clause can lead to incorrect results. It’s crucial to pay attention to the comparison operators and ensure they accurately represent the intended logic.
Remember, when working with dates and time in software, precision and attention to detail are paramount to avoid potential pitfalls and ensure accurate results. In my opinion, it is vital to use unit testing for date time comparison functions.