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

This commit is contained in:
Hypolite Petovan 2018-01-26 19:16:22 -05:00
parent 89602e44da
commit a2ee2b56d2
5 changed files with 23 additions and 12 deletions

View File

@ -416,7 +416,7 @@ function drop_item($id) {
/* arrange the list in years */ /* arrange the list in years */
function list_post_dates($uid, $wall) { function list_post_dates($uid, $wall) {
$dnow = Temporal::timezoneNow(date_default_timezone_get(), 'Y-m-d'); $dnow = Temporal::localNow('Y-m-d');
$dthen = Item::firstPostDate($uid, $wall); $dthen = Item::firstPostDate($uid, $wall);
if (!$dthen) { if (!$dthen) {
@ -474,7 +474,7 @@ function posted_date_widget($url, $uid, $wall) {
return $o; return $o;
} }
$cutoff_year = intval(Temporal::timezoneNow(date_default_timezone_get(), 'Y')) - $visible_years; $cutoff_year = intval(Temporal::localNow('Y')) - $visible_years;
$cutoff = ((array_key_exists($cutoff_year, $ret))? true : false); $cutoff = ((array_key_exists($cutoff_year, $ret))? true : false);
$o = replace_macros(get_markup_template('posted_date_widget.tpl'),[ $o = replace_macros(get_markup_template('posted_date_widget.tpl'),[

View File

@ -152,8 +152,8 @@ function cal_content(App $a)
// The view mode part is similiar to /mod/events.php // The view mode part is similiar to /mod/events.php
if ($mode == 'view') { if ($mode == 'view') {
$thisyear = Temporal::timezoneNow(date_default_timezone_get(), 'Y'); $thisyear = Temporal::localNow('Y');
$thismonth = Temporal::timezoneNow(date_default_timezone_get(), 'm'); $thismonth = Temporal::localNow('m');
if (!$y) { if (!$y) {
$y = intval($thisyear); $y = intval($thisyear);
} }

View File

@ -276,8 +276,8 @@ function events_content(App $a) {
// The view mode part is similiar to /mod/cal.php // The view mode part is similiar to /mod/cal.php
if ($mode == 'view') { if ($mode == 'view') {
$thisyear = Temporal::timezoneNow(date_default_timezone_get(), 'Y'); $thisyear = Temporal::localNow('Y');
$thismonth = Temporal::timezoneNow(date_default_timezone_get(), 'm'); $thismonth = Temporal::localNow('m');
if (! $y) { if (! $y) {
$y = intval($thisyear); $y = intval($thisyear);
} }

View File

@ -402,7 +402,7 @@ function photos_post(App $a)
$resource_id = $a->argv[2]; $resource_id = $a->argv[2];
if (!strlen($albname)) { if (!strlen($albname)) {
$albname = Temporal::timezoneNow(date_default_timezone_get(), 'Y'); $albname = Temporal::localNow('Y');
} }
if (x($_POST,'rotate') !== false && if (x($_POST,'rotate') !== false &&
@ -738,7 +738,7 @@ function photos_post(App $a)
if (strlen($newalbum)) { if (strlen($newalbum)) {
$album = $newalbum; $album = $newalbum;
} else { } else {
$album = Temporal::timezoneNow(date_default_timezone_get(), 'Y'); $album = Temporal::localNow('Y');
} }
} }

View File

@ -136,7 +136,7 @@ class Temporal
} }
/** /**
* convert() shorthand for UTC now. * convert() shorthand for timezoned now.
* *
* @param string $format DateTime format string or Temporal constant * @param string $format DateTime format string or Temporal constant
* @return string * @return string
@ -146,6 +146,17 @@ class Temporal
return self::convert('now', $timezone, 'UTC', $format); return self::convert('now', $timezone, 'UTC', $format);
} }
/**
* convert() shorthand for local now.
*
* @param string $format DateTime format string or Temporal constant
* @return string
*/
public static function localNow($format = self::MYSQL)
{
return self::convert('now', date_default_timezone_get(), 'UTC', $format);
}
/** /**
* convert() shorthand for UTC now. * convert() shorthand for UTC now.
* *
@ -542,8 +553,8 @@ class Temporal
'October', 'November', 'December' 'October', 'November', 'December'
]; ];
$thisyear = self::timezoneNow(date_default_timezone_get(), 'Y'); $thisyear = self::localNow('Y');
$thismonth = self::timezoneNow(date_default_timezone_get(), 'm'); $thismonth = self::localNow('m');
if (!$y) { if (!$y) {
$y = $thisyear; $y = $thisyear;
} }
@ -560,7 +571,7 @@ class Temporal
$started = false; $started = false;
if (($y == $thisyear) && ($m == $thismonth)) { if (($y == $thisyear) && ($m == $thismonth)) {
$tddate = intval(self::timezoneNow(date_default_timezone_get(), 'j')); $tddate = intval(self::localNow('j'));
} }
$str_month = day_translate($mtab[$m]); $str_month = day_translate($mtab[$m]);