From cd5d284d83d0c031be38e3c5d07f6b96b837a42f Mon Sep 17 00:00:00 2001 From: Deeka Wong Date: Wed, 13 Mar 2024 16:47:07 +0800 Subject: [PATCH] Added `now()` and `today()` helper functions (#6579) --- src/Functions.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Functions.php b/src/Functions.php index 23f9ec1..0f46d06 100644 --- a/src/Functions.php +++ b/src/Functions.php @@ -11,7 +11,9 @@ */ namespace Hyperf\Support; +use Carbon\Carbon; use Closure; +use DateTimeZone; use Hyperf\Collection\Arr; use Hyperf\Context\ApplicationContext; use Hyperf\Stringable\StrCache; @@ -264,3 +266,25 @@ function msleep(int $milliSeconds): void { usleep($milliSeconds * 1000); } + +/** + * Create a new Carbon instance for the current time. + * + * @param null|DateTimeZone|string $tz + * @return Carbon + */ +function now($tz = null) +{ + return Carbon::now($tz); +} + +/** + * Create a new Carbon instance for the current date. + * + * @param null|DateTimeZone|string $tz + * @return Carbon + */ +function today($tz = null) +{ + return Carbon::today($tz); +}