Skip to content

Conversation

@SanderMuller
Copy link
Contributor

@SanderMuller SanderMuller commented Dec 2, 2025

This PR adds three missing duration helpers to Illuminate\Support:
milliseconds(), weeks(), and months().
They return CarbonInterval instances, matching the existing seconds, minutes, hours, days, and years helpers.

Why?

These units are commonly used when working with cache TTLs, scheduled tasks, HTTP client timeouts, retry delays, and time-based tests.
While developers can call CarbonInterval::milliseconds() directly, Laravel already standardizes duration helpers as a more readable and consistent API.

Benefits

  • More expressive and complete set of duration helpers
  • Cleaner code for common time calculations
  • No breaking changes (helpers are added behind function_exists)

Edit:
Also added microseconds. I think this is needed less often, but since milliseconds only supports an int value, it will be useful for the project that this PR was created for, since we currently pass a float to CarbonInterval::milliseconds(), which is supported and has the desired effect, despite the docblock only notating int as value in CarbonInterval.
I would also be open to letting milliseconds() accept a int|float, which will probably remove the need for microseconds() for most people

For when a smaller unit than milliseconds is needed, or a decimal value of milliseconds
@SanderMuller SanderMuller changed the title Add milliseconds, weeks, and months duration helpers to Illuminate\Support [12.x] Add milliseconds, weeks, and months duration helpers to Illuminate\Support Dec 2, 2025
@taylorotwell taylorotwell merged commit 7605c76 into laravel:12.x Dec 2, 2025
74 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants