1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 14:00:56 +01:00

Render timezones in event reminder mail, and render them more nicely

Summary:
Fixes T12356.

  - In this mail, we currently render "6:00 AM". Instead, render "6:00 AM (PDT)" or similar. This is consistent with times in other modern Transaction mail.
  - Previously, we would render "UTC-7". Render "PDT" instead. For obscure zones with no known timezone abbreviation, fall back to "UTC-7".

Test Plan:
  - Used `bin/calendar notify --minutes X` to trigger notifications, read email bodies.
  - Used this script to list all `T` values and checked them for sanity:

```lang=php
<?php

$now = new DateTime();

$locales = DateTimeZone::listIdentifiers();
foreach ($locales as $locale) {
  $zone = new DateTimeZone($locale);
  $now->setTimeZone($zone);

  printf(
    "%s (%s)\n",
    $locale,
    $now->format('T'));
}
```

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12356

Differential Revision: https://secure.phabricator.com/D17646
This commit is contained in:
epriestley 2017-04-10 07:44:58 -07:00
parent 50e809e06f
commit 00a1dec7a6
5 changed files with 32 additions and 12 deletions

View file

@ -4692,6 +4692,7 @@ phutil_register_library_map(array(
'javelin_tag' => 'infrastructure/javelin/markup.php',
'phabricator_date' => 'view/viewutils.php',
'phabricator_datetime' => 'view/viewutils.php',
'phabricator_datetimezone' => 'view/viewutils.php',
'phabricator_form' => 'infrastructure/javelin/markup.php',
'phabricator_format_local_time' => 'view/viewutils.php',
'phabricator_relative_date' => 'view/viewutils.php',

View file

@ -58,4 +58,12 @@ final class PhabricatorCalendarEventNotificationView
return phabricator_datetime($epoch, $viewer);
}
public function getDisplayTimeWithTimezone() {
$viewer = $this->getViewer();
$epoch = $this->getEpoch();
return phabricator_datetimezone($epoch, $viewer);
}
}

View file

@ -268,7 +268,7 @@ final class PhabricatorCalendarNotificationEngine
'%s is starting in %s minute(s), at %s.',
$event->getEvent()->getName(),
$event->getDisplayMinutes(),
$event->getDisplayTime()));
$event->getDisplayTimeWithTimezone()));
$body->addLinkSection(
pht('EVENT DETAIL'),

View file

@ -234,22 +234,15 @@ abstract class PhabricatorModularTransactionType
if ($all_day) {
$display = phabricator_date($epoch, $viewer);
} else {
$display = phabricator_datetime($epoch, $viewer);
} else if ($this->isRenderingTargetExternal()) {
// When rendering to text, we explicitly render the offset from UTC to
// provide context to the date: the mail may be generating with the
// server's settings, or the user may later refer back to it after
// changing timezones.
if ($this->isRenderingTargetExternal()) {
$offset = $viewer->getTimeZoneOffsetInHours();
if ($offset >= 0) {
$display = pht('%s (UTC+%d)', $display, $offset);
} else {
$display = pht('%s (UTC-%d)', $display, abs($offset));
}
}
$display = phabricator_datetimezone($epoch, $viewer);
} else {
$display = phabricator_datetime($epoch, $viewer);
}
return $this->renderValue($display);

View file

@ -48,6 +48,24 @@ function phabricator_datetime($epoch, $user) {
$user->getUserSetting($time_key)));
}
function phabricator_datetimezone($epoch, $user) {
$datetime = phabricator_datetime($epoch, $user);
$timezone = phabricator_format_local_time($epoch, $user, 'T');
// Some obscure timezones just render as "+03" or "-09". Make these render
// as "UTC+3" instead.
if (preg_match('/^[+-]/', $timezone)) {
$timezone = (int)trim($timezone, '+');
if ($timezone < 0) {
$timezone = pht('UTC-%s', $timezone);
} else {
$timezone = pht('UTC+%s', $timezone);
}
}
return pht('%s (%s)', $datetime, $timezone);
}
/**
* This function does not usually need to be called directly. Instead, call
* @{function:phabricator_date}, @{function:phabricator_time}, or