From b60a408c564de75b44e0a59c58d58224f50ce8fa Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 20 Nov 2025 14:54:59 -0600 Subject: [PATCH 1/5] initial time functions --- src/Illuminate/Support/functions.php | 53 ++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/Illuminate/Support/functions.php b/src/Illuminate/Support/functions.php index bb596c6539b9..960e91208ad1 100644 --- a/src/Illuminate/Support/functions.php +++ b/src/Illuminate/Support/functions.php @@ -2,6 +2,7 @@ namespace Illuminate\Support; +use Illuminate\Support\Carbon; use Illuminate\Support\Defer\DeferredCallback; use Illuminate\Support\Defer\DeferredCallbackCollection; use Symfony\Component\Process\PhpExecutableFinder; @@ -47,3 +48,55 @@ function artisan_binary(): string return defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan'; } } + +// Time functions... + +if (! function_exists('Illuminate\Support\seconds')) { + /** + * Get the current date / time plus the given number of seconds. + */ + function seconds(int $seconds): Carbon + { + return Carbon::now()->addSeconds($seconds); + } +} + +if (! function_exists('Illuminate\Support\minutes')) { + /** + * Get the current date / time plus the given number of minutes. + */ + function minutes(int $minutes): Carbon + { + return Carbon::now()->addMinutes($minutes); + } +} + +if (! function_exists('Illuminate\Support\hours')) { + /** + * Get the current date / time plus the given number of hours. + */ + function hours(int $hours): Carbon + { + return Carbon::now()->addHours($hours); + } +} + +if (! function_exists('Illuminate\Support\days')) { + /** + * Get the current date / time plus the given number of days. + */ + function days(int $days): Carbon + { + return Carbon::now()->addDays($days); + } +} + +if (! function_exists('Illuminate\Support\years')) { + /** + * Get the current date / time plus the given number of years. + */ + function years(int $years): Carbon + { + return Carbon::now()->addYears($years); + } +} From d26112794f0f41cf7528077c3cdc8944aab0e2da Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 20 Nov 2025 15:05:54 -0600 Subject: [PATCH 2/5] fix time functions --- src/Illuminate/Support/Carbon.php | 38 ++++++++++++++++++++++++++++ src/Illuminate/Support/functions.php | 21 +++++++-------- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/Illuminate/Support/Carbon.php b/src/Illuminate/Support/Carbon.php index bd56ad832988..80d5fb3dc853 100644 --- a/src/Illuminate/Support/Carbon.php +++ b/src/Illuminate/Support/Carbon.php @@ -33,4 +33,42 @@ public static function createFromId(Uuid|Ulid|string $id): static return static::createFromInterface($id->getDateTime()); } + + /** + * Get the current date / time plus a given amount of time. + */ + public function plus( + int $years = 0, + int $months = 0, + int $weeks = 0, + int $days = 0, + int $hours = 0, + int $minutes = 0, + int $seconds = 0, + int $microseconds = 0 + ): static { + return $this->add(" + $years years $months months $weeks weeks $days days + $hours hours $minutes minutes $seconds seconds $microseconds microseconds + "); + } + + /** + * Get the current date / time minus a given amount of time. + */ + public function minus( + int $years = 0, + int $months = 0, + int $weeks = 0, + int $days = 0, + int $hours = 0, + int $minutes = 0, + int $seconds = 0, + int $microseconds = 0 + ): static { + return $this->sub(" + $years years $months months $weeks weeks $days days + $hours hours $minutes minutes $seconds seconds $microseconds microseconds + "); + } } diff --git a/src/Illuminate/Support/functions.php b/src/Illuminate/Support/functions.php index 960e91208ad1..835bbd2d0fef 100644 --- a/src/Illuminate/Support/functions.php +++ b/src/Illuminate/Support/functions.php @@ -2,6 +2,7 @@ namespace Illuminate\Support; +use Carbon\CarbonInterval; use Illuminate\Support\Carbon; use Illuminate\Support\Defer\DeferredCallback; use Illuminate\Support\Defer\DeferredCallbackCollection; @@ -55,9 +56,9 @@ function artisan_binary(): string /** * Get the current date / time plus the given number of seconds. */ - function seconds(int $seconds): Carbon + function seconds(int $seconds): CarbonInterval { - return Carbon::now()->addSeconds($seconds); + return CarbonInterval::seconds($seconds); } } @@ -65,9 +66,9 @@ function seconds(int $seconds): Carbon /** * Get the current date / time plus the given number of minutes. */ - function minutes(int $minutes): Carbon + function minutes(int $minutes): CarbonInterval { - return Carbon::now()->addMinutes($minutes); + return CarbonInterval::minutes($minutes); } } @@ -75,9 +76,9 @@ function minutes(int $minutes): Carbon /** * Get the current date / time plus the given number of hours. */ - function hours(int $hours): Carbon + function hours(int $hours): CarbonInterval { - return Carbon::now()->addHours($hours); + return CarbonInterval::hours($hours); } } @@ -85,9 +86,9 @@ function hours(int $hours): Carbon /** * Get the current date / time plus the given number of days. */ - function days(int $days): Carbon + function days(int $days): CarbonInterval { - return Carbon::now()->addDays($days); + return CarbonInterval::days($days); } } @@ -95,8 +96,8 @@ function days(int $days): Carbon /** * Get the current date / time plus the given number of years. */ - function years(int $years): Carbon + function years(int $years): CarbonInterval { - return Carbon::now()->addYears($years); + return CarbonInterval::years($years); } } From 00a84211690fa14b55a98795e30abea7b06f719e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 20 Nov 2025 15:09:11 -0600 Subject: [PATCH 3/5] add now function --- src/Illuminate/Support/functions.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Illuminate/Support/functions.php b/src/Illuminate/Support/functions.php index 835bbd2d0fef..159d48ebb0a5 100644 --- a/src/Illuminate/Support/functions.php +++ b/src/Illuminate/Support/functions.php @@ -2,6 +2,7 @@ namespace Illuminate\Support; +use Carbon\CarbonInterface; use Carbon\CarbonInterval; use Illuminate\Support\Carbon; use Illuminate\Support\Defer\DeferredCallback; @@ -52,6 +53,19 @@ function artisan_binary(): string // Time functions... +if (! function_exists('Illuminate\Support\now')) { + /** + * Create a new Carbon instance for the current time. + * + * @param \DateTimeZone|\UnitEnum|string|null $tz + * @return \Illuminate\Support\Carbon + */ + function now($tz = null): CarbonInterface + { + return \now($tz); + } +} + if (! function_exists('Illuminate\Support\seconds')) { /** * Get the current date / time plus the given number of seconds. From 0e9b65a2481038fca7604938eb4a4c37fa29bde8 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 21 Nov 2025 10:04:01 -0600 Subject: [PATCH 4/5] formatting --- src/Illuminate/Support/functions.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Support/functions.php b/src/Illuminate/Support/functions.php index 159d48ebb0a5..f93c7471c3b8 100644 --- a/src/Illuminate/Support/functions.php +++ b/src/Illuminate/Support/functions.php @@ -7,6 +7,7 @@ use Illuminate\Support\Carbon; use Illuminate\Support\Defer\DeferredCallback; use Illuminate\Support\Defer\DeferredCallbackCollection; +use Illuminate\Support\Facades\Date; use Symfony\Component\Process\PhpExecutableFinder; if (! function_exists('Illuminate\Support\defer')) { @@ -62,7 +63,7 @@ function artisan_binary(): string */ function now($tz = null): CarbonInterface { - return \now($tz); + return Date::now(enum_value($tz)); } } From c740b2a511cce20a4cf0c91f2b38071e41bf1224 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 21 Nov 2025 16:04:30 +0000 Subject: [PATCH 5/5] Apply fixes from StyleCI --- src/Illuminate/Support/functions.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Illuminate/Support/functions.php b/src/Illuminate/Support/functions.php index f93c7471c3b8..6ae16a07599e 100644 --- a/src/Illuminate/Support/functions.php +++ b/src/Illuminate/Support/functions.php @@ -4,7 +4,6 @@ use Carbon\CarbonInterface; use Carbon\CarbonInterval; -use Illuminate\Support\Carbon; use Illuminate\Support\Defer\DeferredCallback; use Illuminate\Support\Defer\DeferredCallbackCollection; use Illuminate\Support\Facades\Date;