Add Temporal::timezoneNow() shorthand for Temporal::convert()

This commit is contained in:
Hypolite Petovan 2018-01-26 19:14:15 -05:00
parent 35d06bd9eb
commit 89602e44da
8 changed files with 31 additions and 20 deletions

View file

@ -135,6 +135,17 @@ class Temporal
return self::convert($time, 'UTC', 'UTC', $format);
}
/**
* convert() shorthand for UTC now.
*
* @param string $format DateTime format string or Temporal constant
* @return string
*/
public static function timezoneNow($timezone, $format = self::MYSQL)
{
return self::convert('now', $timezone, 'UTC', $format);
}
/**
* convert() shorthand for UTC now.
*
@ -459,9 +470,9 @@ class Temporal
$birthdate = self::convert($dob . ' 00:00:00+00:00', $owner_tz, 'UTC', 'Y-m-d');
list($year, $month, $day) = explode("-", $birthdate);
$year_diff = self::convert('now', $viewer_tz, 'UTC', 'Y') - $year;
$curr_month = self::convert('now', $viewer_tz, 'UTC', 'm');
$curr_day = self::convert('now', $viewer_tz, 'UTC', 'd');
$year_diff = self::timezoneNow($viewer_tz, 'Y') - $year;
$curr_month = self::timezoneNow($viewer_tz, 'm');
$curr_day = self::timezoneNow($viewer_tz, 'd');
if (($curr_month < $month) || (($curr_month == $month) && ($curr_day < $day))) {
$year_diff--;
@ -531,8 +542,8 @@ class Temporal
'October', 'November', 'December'
];
$thisyear = self::convert('now', date_default_timezone_get(), 'UTC', 'Y');
$thismonth = self::convert('now', date_default_timezone_get(), 'UTC', 'm');
$thisyear = self::timezoneNow(date_default_timezone_get(), 'Y');
$thismonth = self::timezoneNow(date_default_timezone_get(), 'm');
if (!$y) {
$y = $thisyear;
}
@ -549,7 +560,7 @@ class Temporal
$started = false;
if (($y == $thisyear) && ($m == $thismonth)) {
$tddate = intval(self::convert('now', date_default_timezone_get(), 'UTC', 'j'));
$tddate = intval(self::timezoneNow(date_default_timezone_get(), 'j'));
}
$str_month = day_translate($mtab[$m]);