A glitch in February of the year 0
a day ago
- #PHP Bug
- #Year 0
- #DateTime
- A bug was discovered in PHP's DateTimeImmutable when parsing timestamps from February in the year 0, affecting all time zones.
- The issue occurred specifically with the method 'new \DateTimeImmutable('@-62164356180')', causing dates to be off by one day for February and late January of the year 0.
- The bug stemmed from timelib, PHP's underlying date/time library, which had an incorrect range check in one algorithm for converting Unix timestamps in century leap years like year 0.
- A workaround was implemented by using alternative conversion methods, such as \DateTimeImmutable::createFromFormat('U', timestamp) or (new \DateTimeImmutable('@0'))->setTimestamp(timestamp).
- A pull request was submitted to fix timelib, ensuring the correct algorithm is used for all timestamp conversions, with hopes for inclusion in future PHP releases.