---
title: "Carbon: date rounding that carries units in PHP | VulCode"
description: "In Carbon we fixed round(), floor() and ceil() with a numeric precision, which only cleared the seconds instead of carrying into hours and days, in PHP."
url: "https://vulcode.com/en/opensource/contributions/carbon"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/contributions)

briannesbitt/Carbon

# Carbon

A PHP DateTime extension for working with dates, standard in the Laravel ecosystem.

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

- **Language**: PHP
- **GitHub stars**: 16,583
- **Merged changes**: 1
- **Project site**: [carbon.nesbot.com](https://carbon.nesbot.com/)

## What we changed

A numeric precision in round(), floor() and ceil() that spans the whole next unit now carries upwards: 3600 seconds rounds to the full hour, and roundMinutes(24 * 60) to the full day.

### What this work shows

- Date and time arithmetic in PHP

- Rounding that carries into larger units

- Regression tests in PHPUnit

What was broken

### round(3600) only cleared the seconds

For a numeric precision Carbon rounded only the seconds value, so from 60 upwards minutes and hours were never touched. round(3600) on 14:21:37 gave 14:21:00, while round('hour') correctly gave 14:00:00.

How we fixed it

### Carried into larger units

A numeric precision that spans the whole next unit is carried upwards: 3600 seconds become an hour, 24 hours a day and 12 months a year. Days are never carried into months, because a month has a varying number of days, and a precision below the next unit works as before.

[#3359](https://github.com/briannesbitt/Carbon/pull/3359)

## Merged change 1

- [#3359 fix: numeric round()/floor()/ceil() precision >= 60 seconds does not carry into minute/hour/day Merged 25 September 2026](https://github.com/briannesbitt/Carbon/pull/3359)

## What it taught us

In date code full of edge cases the safest fix reuses the existing, proven rounding logic instead of writing new logic. After review feedback we extended it to every unit.

[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)

- [**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)

- [**Doctrine Lexer** PHP · 11,141 stars A base for lexers used by recursive descent parsers in PHP, used by Doctrine ORM among others.](https://vulcode.com/en/opensource/contributions/doctrine-lexer)

## 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)
