Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configurable implicit tz and expose to formatting, dev/core #2122 #18841

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CRM/Admin/Form/Setting/Date.php
Expand Up @@ -32,6 +32,7 @@ class CRM_Admin_Form_Setting_Date extends CRM_Admin_Form_Setting {
'dateInputFormat' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'timeInputFormat' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'fiscalYearStart' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'datetzdefault' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
];

/**
Expand Down
19 changes: 19 additions & 0 deletions CRM/Utils/Date.php
Expand Up @@ -413,6 +413,7 @@ public static function customFormat($dateString, $format = NULL, $dateParts = NU
'%P' => $type,
'%A' => $type,
'%Y' => $year,
'%T' => CRM_Utils_Date::getDefaultTimezone(),
];

return strtr($format, $date);
Expand Down Expand Up @@ -2209,4 +2210,22 @@ public static function convertDateToLocalTime($dateObject, $format = 'YmdHis') {
return $dateObject->format($format);
}

/**
* Print out a string representation of the default timezone
* This will allow CiviCRM to automatically handle things like
* daylight savings.
*
* @return string
*/
public static function getDefaultTimezone() {
static $tz_string;
if (empty($tz_string)) {
$dateTzDefault = Civi::settings()->get('datetzdefault');
$dateTime = new DateTime();
$dateTime->setTimeZone(new DateTimeZone($dateTzDefault));
$tz_string = $dateTime->format('T');
}
return $tz_string;
}

}
18 changes: 18 additions & 0 deletions settings/Localization.setting.php
Expand Up @@ -335,6 +335,24 @@
'default' => '%m/%d/%Y',
'title' => ts('Date Format: Short date Month Day Year'),
],
'datetzdefault' => [
'add' => '5',
'help_text' => NULL,
'is_domain' => 1,
'is_contact' => 0,
'group_name' => 'Localization Preferences',
'group' => 'localization',
'name' => 'datetzdefault',
'type' => 'String',
'quick_form_type' => 'Element',
'html_type' => 'text',
'html_attributes' => [
'size' => '12',
'maxlength' => '60',
],
'default' => 'Etc/GMT',
'title' => ts('Implicit time zone: TZ database name'),
],
'dateInputFormat' => [
'add' => '4.7',
'help_text' => NULL,
Expand Down
4 changes: 4 additions & 0 deletions templates/CRM/Admin/Form/Setting/Date.tpl
Expand Up @@ -43,6 +43,10 @@
<td class="label">{$form.dateformatshortdate.label}</td>
<td>{$form.dateformatshortdate.html}</td>
</tr>
<tr class="crm-date-form-block-dateformatTime">
<td class="label">{$form.datetzdefault.label}</td>
<td>{$form.datetzdefault.html}</td>
</tr>
</table>
</fieldset>
<fieldset><legend>{ts}Date Input Fields{/ts}</legend>
Expand Down