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:
Hypolite Petovan
2021-10-03 12:38:47 -04:00
parent 08c24fd4fa
commit 6db211568a
11 changed files with 35 additions and 36 deletions

View File

@@ -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);