1
1
Fork 0

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

This commit is contained in:
Hypolite Petovan 2018-01-26 19:29:06 -05:00
parent 25954314ec
commit 0bee706e51
11 changed files with 48 additions and 36 deletions

View file

@ -790,7 +790,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
'categories' => $categories,
'folders' => $folders,
'text' => strip_tags($body_e),
'localtime' => Temporal::convert($item['created'], date_default_timezone_get(), 'UTC', 'r'),
'localtime' => Temporal::local($item['created'], 'r'),
'ago' => (($item['app']) ? L10n::t('%s from %s', relative_date($item['created']),$item['app']) : relative_date($item['created'])),
'location' => $location_e,
'indent' => '',

View file

@ -28,13 +28,13 @@ function format_event_html($ev, $simple = false) {
$event_start = day_translate(
$ev['adjust'] ?
Temporal::convert($ev['start'], date_default_timezone_get(), 'UTC', $bd_format)
Temporal::local($ev['start'], $bd_format)
: Temporal::utc($ev['start'], $bd_format)
);
$event_end = day_translate(
$ev['adjust'] ?
Temporal::convert($ev['finish'], date_default_timezone_get(), 'UTC', $bd_format)
Temporal::local($ev['finish'], $bd_format)
: Temporal::utc($ev['finish'], $bd_format)
);
@ -200,8 +200,8 @@ function sort_by_date($a) {
function ev_compare($a,$b) {
$date_a = (($a['adjust']) ? Temporal::convert($a['start'], date_default_timezone_get()) : $a['start']);
$date_b = (($b['adjust']) ? Temporal::convert($b['start'], date_default_timezone_get()) : $b['start']);
$date_a = (($a['adjust']) ? Temporal::local($a['start']) : $a['start']);
$date_b = (($b['adjust']) ? Temporal::local($b['start']) : $b['start']);
if ($date_a === $date_b) {
return strcasecmp($a['desc'], $b['desc']);
@ -595,15 +595,15 @@ function process_events($arr) {
$fmt = L10n::t('l, F j');
if (count($arr)) {
foreach ($arr as $rr) {
$j = (($rr['adjust']) ? Temporal::convert($rr['start'], date_default_timezone_get(), 'UTC', 'j') : Temporal::utc($rr['start'], 'j'));
$d = (($rr['adjust']) ? Temporal::convert($rr['start'], date_default_timezone_get(), 'UTC', $fmt) : Temporal::utc($rr['start'], $fmt));
$j = (($rr['adjust']) ? Temporal::local($rr['start'], 'j') : Temporal::utc($rr['start'], 'j'));
$d = (($rr['adjust']) ? Temporal::local($rr['start'], $fmt) : Temporal::utc($rr['start'], $fmt));
$d = day_translate($d);
$start = (($rr['adjust']) ? Temporal::convert($rr['start'], date_default_timezone_get(), 'UTC', 'c') : Temporal::utc($rr['start'], 'c'));
$start = (($rr['adjust']) ? Temporal::local($rr['start'], 'c') : Temporal::utc($rr['start'], 'c'));
if ($rr['nofinish']) {
$end = null;
} else {
$end = (($rr['adjust']) ? Temporal::convert($rr['finish'], date_default_timezone_get(), 'UTC', 'c') : Temporal::utc($rr['finish'], 'c'));
$end = (($rr['adjust']) ? Temporal::local($rr['finish'], 'c') : Temporal::utc($rr['finish'], 'c'));
}
$is_first = ($d !== $last_date);
@ -930,26 +930,26 @@ function format_event_item($item) {
// Convert the time to different formats.
$dtstart_dt = day_translate(
$item['event-adjust'] ?
Temporal::convert($item['event-start'], date_default_timezone_get(), 'UTC', $dformat)
Temporal::local($item['event-start'], $dformat)
: Temporal::utc($item['event-start'], $dformat)
);
$dtstart_title = Temporal::utc($item['event-start'], $item['event-adjust'] ? Temporal::ATOM : 'Y-m-d\TH:i:s');
// Format: Jan till Dec.
$month_short = day_short_translate(
$item['event-adjust'] ?
Temporal::convert($item['event-start'], date_default_timezone_get(), 'UTC', 'M')
Temporal::local($item['event-start'], 'M')
: Temporal::utc($item['event-start'], 'M')
);
// Format: 1 till 31.
$date_short = $item['event-adjust'] ?
Temporal::convert($item['event-start'], date_default_timezone_get(), 'UTC', 'j')
Temporal::local($item['event-start'], 'j')
: Temporal::utc($item['event-start'], 'j');
$start_time = $item['event-adjust'] ?
Temporal::convert($item['event-start'], date_default_timezone_get(), 'UTC', $tformat)
Temporal::local($item['event-start'], $tformat)
: Temporal::utc($item['event-start'], $tformat);
$start_short = day_short_translate(
$item['event-adjust'] ?
Temporal::convert($item['event-start'], date_default_timezone_get(), 'UTC', $dformat_short)
Temporal::local($item['event-start'], $dformat_short)
: Temporal::utc($item['event-start'], $dformat_short)
);
@ -958,17 +958,17 @@ function format_event_item($item) {
$finish = true;
$dtend_dt = day_translate(
$item['event-adjust'] ?
Temporal::convert($item['event-finish'], date_default_timezone_get(), 'UTC', $dformat)
Temporal::local($item['event-finish'], $dformat)
: Temporal::utc($item['event-finish'], $dformat)
);
$dtend_title = Temporal::utc($item['event-finish'], $item['event-adjust'] ? Temporal::ATOM : 'Y-m-d\TH:i:s');
$end_short = day_short_translate(
$item['event-adjust'] ?
Temporal::convert($item['event-finish'], date_default_timezone_get(), 'UTC', $dformat_short)
Temporal::local($item['event-finish'], $dformat_short)
: Temporal::utc($item['event-finish'], $dformat_short)
);
$end_time = $item['event-adjust'] ?
Temporal::convert($item['event-finish'], date_default_timezone_get(), 'UTC', $tformat)
Temporal::local($item['event-finish'], $tformat)
: Temporal::utc($item['event-finish'], $tformat);
// Check if start and finish time is at the same day.
if (substr($dtstart_title, 0, 10) === substr($dtend_title, 0, 10)) {

View file

@ -206,8 +206,8 @@ function cal_content(App $a)
$start = Temporal::utc($start);
$finish = Temporal::utc($finish);
$adjust_start = Temporal::convert($start, date_default_timezone_get());
$adjust_finish = Temporal::convert($finish, date_default_timezone_get());
$adjust_start = Temporal::local($start);
$adjust_finish = Temporal::local($finish);
// put the event parametes in an array so we can better transmit them
$event_params = [
@ -231,7 +231,7 @@ function cal_content(App $a)
if (DBM::is_result($r)) {
$r = sort_by_date($r);
foreach ($r as $rr) {
$j = $rr['adjust'] ? Temporal::convert($rr['start'], date_default_timezone_get(), 'UTC', 'j') : Temporal::utc($rr['start'], 'j');
$j = $rr['adjust'] ? Temporal::local($rr['start'], 'j') : Temporal::utc($rr['start'], 'j');
if (!x($links, $j)) {
$links[$j] = System::baseUrl() . '/' . $a->cmd . '#link-' . $j;
}

View file

@ -540,7 +540,7 @@ function contacts_content(App $a)
$insecure = L10n::t('Private communications are not available for this contact.');
$last_update = (($contact['last-update'] <= NULL_DATE) ? L10n::t('Never') : Temporal::convert($contact['last-update'], date_default_timezone_get(), 'UTC', 'D, j M Y, g:i A'));
$last_update = (($contact['last-update'] <= NULL_DATE) ? L10n::t('Never') : Temporal::local($contact['last-update'], 'D, j M Y, g:i A'));
if ($contact['last-update'] > NULL_DATE) {
$last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? L10n::t("\x28Update was successful\x29") : L10n::t("\x28Update was not successful\x29"));

View file

@ -326,8 +326,8 @@ function events_content(App $a) {
$start = Temporal::utc($start);
$finish = Temporal::utc($finish);
$adjust_start = Temporal::convert($start, date_default_timezone_get());
$adjust_finish = Temporal::convert($finish, date_default_timezone_get());
$adjust_start = Temporal::local($start);
$adjust_finish = Temporal::local($finish);
// put the event parametes in an array so we can better transmit them
$event_params = [
@ -351,7 +351,7 @@ function events_content(App $a) {
if (DBM::is_result($r)) {
$r = sort_by_date($r);
foreach ($r as $rr) {
$j = $rr['adjust'] ? Temporal::convert($rr['start'], date_default_timezone_get(), 'UTC', 'j') : Temporal::utc($rr['start'], 'j');
$j = $rr['adjust'] ? Temporal::local($rr['start'], 'j') : Temporal::utc($rr['start'], 'j');
if (! x($links,$j)) {
$links[$j] = System::baseUrl() . '/' . $a->cmd . '#link-' . $j;
}

View file

@ -397,7 +397,7 @@ function message_content(App $a)
'body' => $body_e,
'delete' => L10n::t('Delete message'),
'to_name' => $to_name_e,
'date' => Temporal::convert($message['created'], date_default_timezone_get(), 'UTC', 'D, d M Y - g:i A'),
'date' => Temporal::local($message['created'], 'D, d M Y - g:i A'),
'ago' => relative_date($message['created']),
];
@ -498,7 +498,7 @@ function render_messages(array $msg, $t)
'$delete' => L10n::t('Delete conversation'),
'$body' => $body_e,
'$to_name' => $to_name_e,
'$date' => Temporal::convert($rr['mailcreated'], date_default_timezone_get(), 'UTC', L10n::t('D, d M Y - g:i A')),
'$date' => Temporal::local($rr['mailcreated'], L10n::t('D, d M Y - g:i A')),
'$ago' => relative_date($rr['mailcreated']),
'$seen' => $rr['mailseen'],
'$count' => L10n::tt('%d message', '%d messages', $rr['count']),

View file

@ -362,7 +362,7 @@ function ping_init(App $a)
$notif['photo'] = proxy_url($notif['photo'], false, PROXY_SIZE_MICRO);
}
$local_time = Temporal::convert($notif['date'], date_default_timezone_get());
$local_time = Temporal::local($notif['date']);
$notifications[] = [
'id' => $notif['id'],

View file

@ -725,7 +725,7 @@ function profiles_content(App $a) {
'$gender' => ContactSelector::gender($r[0]['gender']),
'$marital' => ContactSelector::maritalStatus($r[0]['marital']),
'$with' => ['with', L10n::t("Who: \x28if applicable\x29"), strip_tags($r[0]['with']), L10n::t('Examples: cathy123, Cathy Williams, cathy@example.com')],
'$howlong' => ['howlong', L10n::t('Since [date]:'), ($r[0]['howlong'] <= NULL_DATE ? '' : Temporal::convert($r[0]['howlong'], date_default_timezone_get()))],
'$howlong' => ['howlong', L10n::t('Since [date]:'), ($r[0]['howlong'] <= NULL_DATE ? '' : Temporal::local($r[0]['howlong']))],
'$sexual' => ContactSelector::sexualPreference($r[0]['sexual']),
'$about' => ['about', L10n::t('Tell us about yourself...'), $r[0]['about']],
'$xmpp' => ['xmpp', L10n::t("XMPP \x28Jabber\x29 address:"), $r[0]['xmpp'], L10n::t("The XMPP address will be propagated to your contacts so that they can follow you.")],

View file

@ -43,7 +43,7 @@ class NotificationsManager extends BaseObject
{
$rets = [];
foreach ($notes as $n) {
$local_time = Temporal::convert($n['date'], date_default_timezone_get());
$local_time = Temporal::local($n['date']);
$n['timestamp'] = strtotime($local_time);
$n['date_rel'] = relative_date($n['date']);
$n['msg_html'] = bbcode($n['msg'], false, false, false, false);
@ -244,7 +244,7 @@ class NotificationsManager extends BaseObject
$default_item_image = proxy_url($it['photo'], false, PROXY_SIZE_MICRO);
$default_item_url = $it['url'];
$default_item_text = strip_tags(bbcode($it['msg']));
$default_item_when = Temporal::convert($it['date'], date_default_timezone_get(), 'UTC', 'r');
$default_item_when = Temporal::local($it['date'], 'r');
$default_item_ago = relative_date($it['date']);
break;
@ -254,7 +254,7 @@ class NotificationsManager extends BaseObject
$default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO);
$default_item_url = $it['author-link'];
$default_item_text = L10n::t("%s commented on %s's post", $it['author-name'], $it['pname']);
$default_item_when = Temporal::convert($it['created'], date_default_timezone_get(), 'UTC', 'r');
$default_item_when = Temporal::local($it['created'], 'r');
$default_item_ago = relative_date($it['created']);
break;
@ -266,7 +266,7 @@ class NotificationsManager extends BaseObject
$default_item_text = (($it['id'] == $it['parent'])
? L10n::t("%s created a new post", $it['author-name'])
: L10n::t("%s commented on %s's post", $it['author-name'], $it['pname']));
$default_item_when = Temporal::convert($it['created'], date_default_timezone_get(), 'UTC', 'r');
$default_item_when = Temporal::local($it['created'], 'r');
$default_item_ago = relative_date($it['created']);
}

View file

@ -124,7 +124,7 @@ class Post extends BaseObject
if (strtotime($item['edited']) - strtotime($item['created']) > 1) {
$edited = [
'label' => L10n::t('This entry was edited'),
'date' => Temporal::convert($item['edited'], date_default_timezone_get(), 'UTC', 'r'),
'date' => Temporal::local($item['edited'], 'r'),
'relative' => relative_date($item['edited'])
];
}
@ -364,7 +364,7 @@ class Post extends BaseObject
'osparkle' => $osparkle,
'sparkle' => $sparkle,
'title' => $title_e,
'localtime' => Temporal::convert($item['created'], date_default_timezone_get(), 'UTC', 'r'),
'localtime' => Temporal::local($item['created'], 'r'),
'ago' => $item['app'] ? L10n::t('%s from %s', relative_date($item['created']), $item['app']) : relative_date($item['created']),
'app' => $item['app'],
'created' => relative_date($item['created']),

View file

@ -135,6 +135,18 @@ class Temporal
return self::convert($time, 'UTC', 'UTC', $format);
}
/**
* convert() shorthand for local.
*
* @param string $time A date/time string
* @param string $format DateTime format string or Temporal constant
* @return string
*/
public static function local($time, $format = self::MYSQL)
{
return self::convert($time, date_default_timezone_get(), 'UTC', $format);
}
/**
* convert() shorthand for timezoned now.
*
@ -154,7 +166,7 @@ class Temporal
*/
public static function localNow($format = self::MYSQL)
{
return self::convert('now', date_default_timezone_get(), 'UTC', $format);
return self::local('now', $format);
}
/**
@ -165,7 +177,7 @@ class Temporal
*/
public static function utcNow($format = self::MYSQL)
{
return self::convert('now', 'UTC', 'UTC', $format);
return self::utc('now', $format);
}
/**