All contributions

cakephp/chronos

Chronos

A standalone PHP date and time library from the CakePHP team, originally based on Carbon. It also has a ChronosTime type for a time of day on its own.

Language
PHP
GitHub stars
1,361
Merged changes
1
Project site
book.cakephp.org

What we changed

Fractional seconds in ChronosTime are parsed as a fraction of a second, not as a count of microseconds, the same way DateTime does it.

What this work shows

  • Parsing times and fractional seconds
  • Matching PHP's DateTime behaviour
  • Unit tests in PHPUnit
What was broken

12:00:00.5 meant 5 microseconds

ChronosTime read the digits after the dot as a count of microseconds, so 12:00:00.5 became 5 microseconds instead of half a second, unlike PHP's own DateTime. Only a full six-digit fraction worked, and that was all the existing tests used.

How we fixed it

The fraction is padded to microseconds

parseString() right-pads the fraction digits with zeros to six before converting them: .5 is 500000 and .05 is 50000 microseconds. Six-digit and longer fractions, truncated to six digits, work as before, and a new test covers three fraction lengths.

#531

Merged change 1

  1. #531 fix: parse fractional seconds in ChronosTime as a fraction of a second Merged 6 September 2026

What it taught us

A parsing bug slipped through every existing test, because each used a full six digits. We add the shorter cases and compare the result with the built-in DateTime.

More about this technology: PHP

Other projects we write code for

Describe your project.

A free quote comes back within an hour during working hours.