Remove most calls to date_default_timezone_* calls
- It was wrongly used to set the node-wide ot user-specific timezone - It is now fully managed from the App object - Add a static variable to DateTimeFormat maintain the convenient local() method
This commit is contained in:
parent
08c24fd4fa
commit
6db211568a
11 changed files with 35 additions and 36 deletions
|
@ -36,6 +36,13 @@ class DateTimeFormat
|
|||
const HTTP = 'D, d M Y H:i:s \G\M\T';
|
||||
const JSON = 'Y-m-d\TH:i:s.v\Z';
|
||||
|
||||
static $localTimezone = 'UTC';
|
||||
|
||||
public static function setLocalTimeZone(string $timezone)
|
||||
{
|
||||
self::$localTimezone = $timezone;
|
||||
}
|
||||
|
||||
/**
|
||||
* convert() shorthand for UTC.
|
||||
*
|
||||
|
@ -59,7 +66,7 @@ class DateTimeFormat
|
|||
*/
|
||||
public static function local($time, $format = self::MYSQL)
|
||||
{
|
||||
return self::convert($time, date_default_timezone_get(), 'UTC', $format);
|
||||
return self::convert($time, self::$localTimezone, 'UTC', $format);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -160,7 +167,7 @@ class DateTimeFormat
|
|||
$to_obj = new DateTimeZone('UTC');
|
||||
}
|
||||
|
||||
$d->setTimeZone($to_obj);
|
||||
$d->setTimezone($to_obj);
|
||||
|
||||
return $d->format($format);
|
||||
}
|
||||
|
|
|
@ -360,23 +360,19 @@ class Temporal
|
|||
* Returns the age in years, given a date of birth and the timezone of the person
|
||||
* whose date of birth is provided.
|
||||
*
|
||||
* @param string $dob Date of Birth
|
||||
* @param string $owner_tz (optional) Timezone of the person of interest
|
||||
* @param string $dob Date of Birth
|
||||
* @param string $timezone Timezone of the person of interest
|
||||
*
|
||||
* @return int Age in years
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getAgeByTimezone($dob, $owner_tz = ''): int
|
||||
public static function getAgeByTimezone(string $dob, string $timezone): int
|
||||
{
|
||||
if (!intval($dob)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!$owner_tz) {
|
||||
$owner_tz = date_default_timezone_get();
|
||||
}
|
||||
|
||||
$birthdate = new DateTime($dob . ' 00:00:00', new DateTimeZone($owner_tz));
|
||||
$birthdate = new DateTime($dob . ' 00:00:00', new DateTimeZone($timezone));
|
||||
$currentDate = new DateTime('now', new DateTimeZone('UTC'));
|
||||
|
||||
$interval = $birthdate->diff($currentDate);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue