---
title: "Chronos: fractional seconds in ChronosTime, PHP | VulCode"
description: "A fix in Chronos, the CakePHP date library for PHP: ChronosTime reads fractional seconds like DateTime, so 12:00:00.5 is half a second, not 5 microseconds."
url: "https://vulcode.com/en/opensource/contributions/chronos"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/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.

[See the repository](https://github.com/cakephp/chronos) [All contributions](https://vulcode.com/en/opensource/contributions)

- **Language**: PHP
- **GitHub stars**: 1,361
- **Merged changes**: 1
- **Project site**: [book.cakephp.org](http://book.cakephp.org/chronos)

## 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](https://github.com/cakephp/chronos/pull/531)

## Merged change 1

- [#531 fix: parse fractional seconds in ChronosTime as a fraction of a second Merged 6 September 2026](https://github.com/cakephp/chronos/pull/531)

## 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](https://vulcode.com/en/technologies/php)

## Other projects we write code for

- [**Composer** PHP · 29,590 stars The dependency manager for PHP: it installs and updates a project's libraries from its composer.json.](https://vulcode.com/en/opensource/contributions/composer)

- [**PHPMailer** PHP · 22,347 stars The classic PHP library for sending email, used by WordPress and many other systems.](https://vulcode.com/en/opensource/contributions/phpmailer)

- [**Monolog** PHP · 21,407 stars A PHP logging library that sends records to files, sockets, inboxes, databases and web services. Symfony and Laravel use it, among others.](https://vulcode.com/en/opensource/contributions/monolog)

- [**Carbon** PHP · 16,583 stars A PHP DateTime extension for working with dates, standard in the Laravel ecosystem.](https://vulcode.com/en/opensource/contributions/carbon)

- [**Whoops** PHP · 13,231 stars A PHP library that turns uncaught exceptions into a readable error page with the stack trace, known from Laravel.](https://vulcode.com/en/opensource/contributions/whoops)

- [**ramsey/uuid** PHP · 12,642 stars A PHP library for generating universally unique identifiers (UUIDs).](https://vulcode.com/en/opensource/contributions/ramsey-uuid)

## Describe your project.

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

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)
