Skip to content
Snippets Groups Projects
Commit a55ce6c3 authored by Jared Hancock's avatar Jared Hancock
Browse files

i18n: Convert datetime formats on upgrade to ICU

parent 71a7e106
No related branches found
No related tags found
No related merge requests found
...@@ -101,8 +101,7 @@ class ClientCreateRequest { ...@@ -101,8 +101,7 @@ class ClientCreateRequest {
$this_form = UserForm::getUserForm()->getForm($this->getInfo()); $this_form = UserForm::getUserForm()->getForm($this->getInfo());
$bk = $this->getBackend(); $bk = $this->getBackend();
$defaults = array( $defaults = array(
'timezone_id' => $cfg->getDefaultTimezoneId(), 'timezone' => $cfg->getDefaultTimezone(),
'dst' => $cfg->observeDaylightSaving(),
'username' => $this->getUsername(), 'username' => $this->getUsername(),
); );
if ($bk->supportsInteractiveAuthentication()) if ($bk->supportsInteractiveAuthentication())
......
...@@ -178,17 +178,6 @@ class OsticketConfig extends Config { ...@@ -178,17 +178,6 @@ class OsticketConfig extends Config {
$this->config[$key] = array('value'=>$value); $this->config[$key] = array('value'=>$value);
} }
//Get the default time zone
// We can't JOIN timezone table above due to upgrade support.
if ($this->get('default_timezone_id')) {
if (!$this->exists('tz_offset'))
$this->persist('tz_offset',
Timezone::getOffsetById($this->get('default_timezone_id')));
} else
// Previous osTicket versions saved the offset value instead of
// a timezone instance. This is compatibility for the upgrader
$this->persist('tz_offset', 0);
return true; return true;
} }
...@@ -275,9 +264,6 @@ class OsticketConfig extends Config { ...@@ -275,9 +264,6 @@ class OsticketConfig extends Config {
} }
/* Date & Time Formats */ /* Date & Time Formats */
function observeDaylightSaving() {
return ($this->get('enable_daylight_saving'));
}
function getTimeFormat() { function getTimeFormat() {
if ($this->get('date_formats') == 'custom') if ($this->get('date_formats') == 'custom')
return $this->get('time_format'); return $this->get('time_format');
...@@ -286,6 +272,18 @@ class OsticketConfig extends Config { ...@@ -286,6 +272,18 @@ class OsticketConfig extends Config {
function isForce24HourTime() { function isForce24HourTime() {
return $this->get('date_formats') == '24'; return $this->get('date_formats') == '24';
} }
/**
* getDateFormat
*
* Retrieve the current date format for the system, as a string, and in
* the intl (icu) format.
*
* Parameters:
* $propogate - (boolean:default=false), if set and the configuration
* indicates default date and time formats (ie. not custom), then
* the intl date formatter will be queried to find the pattern used
* internally for the current locale settings.
*/
function getDateFormat($propogate=false) { function getDateFormat($propogate=false) {
if ($this->get('date_formats') == 'custom') if ($this->get('date_formats') == 'custom')
return $this->get('date_format'); return $this->get('date_format');
...@@ -336,10 +334,6 @@ class OsticketConfig extends Config { ...@@ -336,10 +334,6 @@ class OsticketConfig extends Config {
return rtrim($this->getUrl(),'/'); return rtrim($this->getUrl(),'/');
} }
function getTZOffset() {
return $this->get('tz_offset');
}
function getPageSize() { function getPageSize() {
return $this->get('max_page_size'); return $this->get('max_page_size');
} }
......
...@@ -150,10 +150,6 @@ class Staff extends AuthenticatedUser { ...@@ -150,10 +150,6 @@ class Staff extends AuthenticatedUser {
return $this->isPasswdResetDue(); return $this->isPasswdResetDue();
} }
function observeDaylight() {
return $this->ht['daylight_saving']?true:false;
}
function getRefreshRate() { function getRefreshRate() {
return $this->ht['auto_refresh_rate']; return $this->ht['auto_refresh_rate'];
} }
......
...@@ -81,13 +81,15 @@ default_name_formatting: ...@@ -81,13 +81,15 @@ default_name_formatting:
date_time_options: date_time_options:
title: Date & Time Options title: Date & Time Options
content: > content: >
The following settings define the Date & Time settings for The following settings define the default settings for Date &
Clients. You can change how these appear by following the PHP date Time settings for the help desk. You can choose to use the locale
format characters. The dates shown below simply illustrate the defaults for the selected locale or use customize the formats to
result of their corresponding values. meet your unique requirements. Refer to the ICU format strings as a
reference for customization. The dates shown below simply
illustrate the result of their corresponding values.
links: links:
- title: See the PHP Date Formatting Table - title: See the ICU Date Formatting Table
href: http://www.php.net/manual/en/function.date.php href: http://userguide.icu-project.org/formatparse/datetime
languages: languages:
title: System Languages title: System Languages
......
<?php
class IntlMigrator extends MigrationTask {
static $dateToIntl = array(
'd' => 'dd',
'D' => 'EEE',
'j' => 'd',
'l' => 'EEEE',
'N' => 'e',
'w' => 'c',
'z' => 'D',
'W' => 'w',
'F' => 'MMMM',
'm' => 'MM',
'M' => 'MMM',
'n' => 'M',
'o' => 'Y',
'Y' => 'y',
'y' => 'yy',
'A' => 'a',
'g' => 'h',
'G' => 'H',
'h' => 'hh',
'H' => 'HH',
'i' => 'mm',
's' => 'ss',
'u' => 'SSSSSS',
'e' => 'VV',
'O' => 'ZZZ',
'P' => 'ZZZZZ',
'T' => 'z',
'c' => "yyyy-MM-dd'T'HH:mm:ssXXXXX",
'r' => 'EEE, d MMM yyyy HH:mm:ss XXXXX',
);
function run($max_time) {
global $cfg;
// Detect rough install date — rationale: the schema_signature is
// touched by the database migrater; however the updated timestamp
// associated with it is not touched.
$install_date = $cfg->lastModified('schema_signature');
$touched = false;
// Upgrade date formats
foreach (
array('datetime_format', 'daydatetime_format', 'time_format', 'date_format')
as $key
) {
$new_format = '';
$format = $cfg->get($key);
foreach (str_split($format) as $char) {
$new_format .= @$dateToIntl[$char] ?: $char;
}
$cfg->set($key, $new_format);
// Consider the last-updated time of the key to see if the
// format has been modified since installation
$touched |= $cfg->lastModified($key) != $install_date;
}
// Add in new custom date format flag
$cfg->set('date_formats', $touched ? 'custom' : '' );
}
}
return 'IntlMigrator';
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment