Skip to content

Commit

Permalink
Customizable implicit timezone setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
adixon committed Oct 22, 2020
1 parent 0f38eb3 commit 936a626
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
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

0 comments on commit 936a626

Please sign in to comment.