Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/Support/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,26 @@

class Utils
{
/**
* Get the timezone from Carbon.
*
* @return string
*/
protected static function getTimezone()
{
$tz = Carbon::now()->getTimezone()->getName();

return in_array($tz, timezone_identifiers_list()) ? $tz : 'UTC';
}

/**
* Get the Carbon instance for the current time.
*
* @return \Carbon\Carbon
*/
public static function now()
{
return Carbon::now('UTC');
return Carbon::now(static::getTimezone());
}

/**
Expand All @@ -33,7 +45,7 @@ public static function now()
*/
public static function timestamp($timestamp)
{
return Carbon::createFromTimestampUTC($timestamp)->timezone('UTC');
return Carbon::createFromTimestampUTC($timestamp)->timezone(static::getTimezone());
}

/**
Expand Down