All contributions

briannesbitt/Carbon

Carbon

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

Language
PHP
GitHub stars
16,583
Merged changes
1
Project site
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

Merged change 1

  1. #3359 fix: numeric round()/floor()/ceil() precision >= 60 seconds does not carry into minute/hour/day Merged 25 September 2026

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

Other projects we write code for

Describe your project.

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