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:
@@ -4692,6 +4692,7 @@ phutil_register_library_map(array(
|
|||||||
'javelin_tag' => 'infrastructure/javelin/markup.php',
|
'javelin_tag' => 'infrastructure/javelin/markup.php',
|
||||||
'phabricator_date' => 'view/viewutils.php',
|
'phabricator_date' => 'view/viewutils.php',
|
||||||
'phabricator_datetime' => 'view/viewutils.php',
|
'phabricator_datetime' => 'view/viewutils.php',
|
||||||
|
'phabricator_datetimezone' => 'view/viewutils.php',
|
||||||
'phabricator_form' => 'infrastructure/javelin/markup.php',
|
'phabricator_form' => 'infrastructure/javelin/markup.php',
|
||||||
'phabricator_format_local_time' => 'view/viewutils.php',
|
'phabricator_format_local_time' => 'view/viewutils.php',
|
||||||
'phabricator_relative_date' => 'view/viewutils.php',
|
'phabricator_relative_date' => 'view/viewutils.php',
|
||||||
|
|||||||
@@ -58,4 +58,12 @@ final class PhabricatorCalendarEventNotificationView
|
|||||||
return phabricator_datetime($epoch, $viewer);
|
return phabricator_datetime($epoch, $viewer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDisplayTimeWithTimezone() {
|
||||||
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
|
$epoch = $this->getEpoch();
|
||||||
|
return phabricator_datetimezone($epoch, $viewer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ final class PhabricatorCalendarNotificationEngine
|
|||||||
'%s is starting in %s minute(s), at %s.',
|
'%s is starting in %s minute(s), at %s.',
|
||||||
$event->getEvent()->getName(),
|
$event->getEvent()->getName(),
|
||||||
$event->getDisplayMinutes(),
|
$event->getDisplayMinutes(),
|
||||||
$event->getDisplayTime()));
|
$event->getDisplayTimeWithTimezone()));
|
||||||
|
|
||||||
$body->addLinkSection(
|
$body->addLinkSection(
|
||||||
pht('EVENT DETAIL'),
|
pht('EVENT DETAIL'),
|
||||||
|
|||||||
@@ -234,22 +234,15 @@ abstract class PhabricatorModularTransactionType
|
|||||||
|
|
||||||
if ($all_day) {
|
if ($all_day) {
|
||||||
$display = phabricator_date($epoch, $viewer);
|
$display = phabricator_date($epoch, $viewer);
|
||||||
} else {
|
} else if ($this->isRenderingTargetExternal()) {
|
||||||
$display = phabricator_datetime($epoch, $viewer);
|
|
||||||
|
|
||||||
// When rendering to text, we explicitly render the offset from UTC to
|
// When rendering to text, we explicitly render the offset from UTC to
|
||||||
// provide context to the date: the mail may be generating with the
|
// 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
|
// server's settings, or the user may later refer back to it after
|
||||||
// changing timezones.
|
// changing timezones.
|
||||||
|
|
||||||
if ($this->isRenderingTargetExternal()) {
|
$display = phabricator_datetimezone($epoch, $viewer);
|
||||||
$offset = $viewer->getTimeZoneOffsetInHours();
|
} else {
|
||||||
if ($offset >= 0) {
|
$display = phabricator_datetime($epoch, $viewer);
|
||||||
$display = pht('%s (UTC+%d)', $display, $offset);
|
|
||||||
} else {
|
|
||||||
$display = pht('%s (UTC-%d)', $display, abs($offset));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->renderValue($display);
|
return $this->renderValue($display);
|
||||||
|
|||||||
@@ -48,6 +48,24 @@ function phabricator_datetime($epoch, $user) {
|
|||||||
$user->getUserSetting($time_key)));
|
$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
|
* This function does not usually need to be called directly. Instead, call
|
||||||
* @{function:phabricator_date}, @{function:phabricator_time}, or
|
* @{function:phabricator_date}, @{function:phabricator_time}, or
|
||||||
|
|||||||
Reference in New Issue
Block a user