From 89602e44da535697dcf33aa37e43cce317d4830c Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 26 Jan 2018 19:14:15 -0500 Subject: [PATCH] Add Temporal::timezoneNow() shorthand for Temporal::convert() --- boot.php | 4 ++-- include/items.php | 4 ++-- mod/cal.php | 4 ++-- mod/events.php | 4 ++-- mod/photos.php | 4 ++-- mod/ping.php | 2 +- src/Model/Profile.php | 6 +++--- src/Util/Temporal.php | 23 +++++++++++++++++------ 8 files changed, 31 insertions(+), 20 deletions(-) diff --git a/boot.php b/boot.php index 18c76587c0..66e4645e5c 100644 --- a/boot.php +++ b/boot.php @@ -1142,10 +1142,10 @@ function feed_birthday($uid, $tz) if (DBM::is_result($p)) { $tmp_dob = substr($p[0]['dob'], 5); if (intval($tmp_dob)) { - $y = Temporal::convert('now', $tz, $tz, 'Y'); + $y = Temporal::timezoneNow($tz, 'Y'); $bd = $y . '-' . $tmp_dob . ' 00:00'; $t_dob = strtotime($bd); - $now = strtotime(Temporal::convert('now', $tz, $tz)); + $now = strtotime(Temporal::timezoneNow($tz)); if ($t_dob < $now) { $bd = $y + 1 . '-' . $tmp_dob . ' 00:00'; } diff --git a/include/items.php b/include/items.php index 83b3484d0d..b5ec592e00 100644 --- a/include/items.php +++ b/include/items.php @@ -416,7 +416,7 @@ function drop_item($id) { /* arrange the list in years */ function list_post_dates($uid, $wall) { - $dnow = Temporal::convert('now', date_default_timezone_get(), 'UTC', 'Y-m-d'); + $dnow = Temporal::timezoneNow(date_default_timezone_get(), 'Y-m-d'); $dthen = Item::firstPostDate($uid, $wall); if (!$dthen) { @@ -474,7 +474,7 @@ function posted_date_widget($url, $uid, $wall) { return $o; } - $cutoff_year = intval(Temporal::convert('now', date_default_timezone_get(), 'UTC', 'Y')) - $visible_years; + $cutoff_year = intval(Temporal::timezoneNow(date_default_timezone_get(), 'Y')) - $visible_years; $cutoff = ((array_key_exists($cutoff_year, $ret))? true : false); $o = replace_macros(get_markup_template('posted_date_widget.tpl'),[ diff --git a/mod/cal.php b/mod/cal.php index 10298aceea..11a1a5e6f9 100644 --- a/mod/cal.php +++ b/mod/cal.php @@ -152,8 +152,8 @@ function cal_content(App $a) // The view mode part is similiar to /mod/events.php if ($mode == 'view') { - $thisyear = Temporal::convert('now', date_default_timezone_get(), 'UTC', 'Y'); - $thismonth = Temporal::convert('now', date_default_timezone_get(), 'UTC', 'm'); + $thisyear = Temporal::timezoneNow(date_default_timezone_get(), 'Y'); + $thismonth = Temporal::timezoneNow(date_default_timezone_get(), 'm'); if (!$y) { $y = intval($thisyear); } diff --git a/mod/events.php b/mod/events.php index 9462b36b0c..aad56f43aa 100644 --- a/mod/events.php +++ b/mod/events.php @@ -276,8 +276,8 @@ function events_content(App $a) { // The view mode part is similiar to /mod/cal.php if ($mode == 'view') { - $thisyear = Temporal::convert('now', date_default_timezone_get(), 'UTC', 'Y'); - $thismonth = Temporal::convert('now', date_default_timezone_get(), 'UTC', 'm'); + $thisyear = Temporal::timezoneNow(date_default_timezone_get(), 'Y'); + $thismonth = Temporal::timezoneNow(date_default_timezone_get(), 'm'); if (! $y) { $y = intval($thisyear); } diff --git a/mod/photos.php b/mod/photos.php index a7ed50a44c..dac52b1d05 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -402,7 +402,7 @@ function photos_post(App $a) $resource_id = $a->argv[2]; if (!strlen($albname)) { - $albname = Temporal::convert('now', date_default_timezone_get(), 'UTC', 'Y'); + $albname = Temporal::timezoneNow(date_default_timezone_get(), 'Y'); } if (x($_POST,'rotate') !== false && @@ -738,7 +738,7 @@ function photos_post(App $a) if (strlen($newalbum)) { $album = $newalbum; } else { - $album = Temporal::convert('now', date_default_timezone_get(), 'UTC', 'Y'); + $album = Temporal::timezoneNow(date_default_timezone_get(), 'Y'); } } diff --git a/mod/ping.php b/mod/ping.php index dd0817d0af..d26fc61bef 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -237,7 +237,7 @@ function ping_init(App $a) $all_events = count($ev); if ($all_events) { - $str_now = Temporal::convert('now', $a->timezone, 'UTC', 'Y-m-d'); + $str_now = Temporal::timezoneNow($a->timezone, 'Y-m-d'); foreach ($ev as $x) { $bd = false; if ($x['type'] === 'birthday') { diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 1cbe5b9b81..aeb7155f19 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -659,7 +659,7 @@ class Profile } $strt = Temporal::convert($rr['start'], $rr['convert'] ? $a->timezone : 'UTC', 'UTC', 'Y-m-d'); - if ($strt === Temporal::convert('now', $a->timezone, 'UTC', 'Y-m-d')) { + if ($strt === Temporal::timezoneNow($a->timezone, 'Y-m-d')) { $istoday = true; } @@ -676,11 +676,11 @@ class Profile $strt = Temporal::convert($rr['start'], $rr['convert'] ? $a->timezone : 'UTC'); - if (substr($strt, 0, 10) < Temporal::convert('now', $a->timezone, 'UTC', 'Y-m-d')) { + if (substr($strt, 0, 10) < Temporal::timezoneNow($a->timezone, 'Y-m-d')) { continue; } - $today = ((substr($strt, 0, 10) === Temporal::convert('now', $a->timezone, 'UTC', 'Y-m-d')) ? true : false); + $today = ((substr($strt, 0, 10) === Temporal::timezoneNow($a->timezone, 'Y-m-d')) ? true : false); $rr['title'] = $title; $rr['description'] = $description; diff --git a/src/Util/Temporal.php b/src/Util/Temporal.php index a2d4677f29..37be4eb919 100644 --- a/src/Util/Temporal.php +++ b/src/Util/Temporal.php @@ -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]);