Skip to content

Commit ef666f2

Browse files
feat(utils): make Carbon timezone dynamic instead of hardcoded UTC
1 parent 152f571 commit ef666f2

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/Support/Utils.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,26 @@
1515

1616
class Utils
1717
{
18+
/**
19+
* Get the timezone from Carbon
20+
*
21+
* @return string
22+
*/
23+
protected static function getTimezone()
24+
{
25+
$tz = Carbon::now()->getTimezone()->getName();
26+
27+
return in_array($tz, timezone_identifiers_list()) ? $tz : 'UTC';
28+
}
29+
1830
/**
1931
* Get the Carbon instance for the current time.
2032
*
2133
* @return \Carbon\Carbon
2234
*/
2335
public static function now()
2436
{
25-
return Carbon::now('UTC');
37+
return Carbon::now(static::getTimezone());
2638
}
2739

2840
/**
@@ -33,7 +45,7 @@ public static function now()
3345
*/
3446
public static function timestamp($timestamp)
3547
{
36-
return Carbon::createFromTimestampUTC($timestamp)->timezone('UTC');
48+
return Carbon::createFromTimestampUTC($timestamp)->timezone(static::getTimezone());
3749
}
3850

3951
/**

0 commit comments

Comments
 (0)