Commit 6c0b290c authored by Côme Bernigaud's avatar Côme Bernigaud Committed by Benoit Mortier
Browse files

Fixes #3622 Added help for working with timezones in timezone class

parent 9e50db68
......@@ -69,7 +69,7 @@ if (($config->get_cfg_value("forcessl") == "TRUE") && ($ssl != '')) {
exit;
}
timezone::get_default_timezone();
timezone::setDefaultTimezoneFromConfig();
/* Check for invalid sessions */
if (session::global_get('_LAST_PAGE_REQUEST') == "") {
......
......@@ -445,6 +445,8 @@ class config {
session::global_set('DEBUGLEVEL', $debugLevel);
IconTheme::loadThemes('themes');
timezone::setDefaultTimezoneFromConfig();
}
......
......@@ -29,44 +29,60 @@
* \brief This class contains all the function needed to manage the
* timezones
*/
class timezone {
class timezone
{
/*
* \brief This function sets the default timezone according to fusiondirectory configuration.
*
* \return TRUE upon success, FALSE otherwise
*/
static public function setDefaultTimezoneFromConfig()
{
global $config;
/* Is there a timezone set in the fusiondirectory configuration */
if ($config->get_cfg_value('timezone') != '') {
$tz = $config->get_cfg_value('timezone');
if (@date_default_timezone_set($tz)) {
return TRUE;
} else {
msg_dialog::display(
_('Configuration error'),
sprintf(_('The timezone setting "%s" in your configuration is not valid.'), $tz),
ERROR_DIALOG
);
}
}
return FALSE;
}
/*
* \brief This function returns the offset for the default timezone.
*
* deprecated
* \param $stamp is used to detect summer or winter time.
* In case of PHP5, the integrated timezone functions are used.
*/
static public function get_default_timezone($stamp = NULL)
{
global $config;
$tz = "";
/* Default return value if zone could not be detected */
$zone = array("name" => "unconfigured", "value" => 0);
/* Use current timestamp if $stamp is not set */
if ($stamp === NULL) {
$stamp = time();
}
/* Is there a timezone configured in the fusiondirectory configuration (fusiondirectory.conf) */
if ($config->get_cfg_value("timezone") != "") {
/* Get zonename */
$tz = $config->get_cfg_value("timezone");
if (!@date_default_timezone_set($tz)) {
msg_dialog::display(_("Configuration error"), sprintf(_("The timezone setting '%s' in your configuration is not valid. Cannot calculate correct timezone offset."), $tz), ERROR_DIALOG);
}
$tz_delta = date("Z", $stamp);
/* Is there a correct timezone set in the fusiondirectory configuration */
if (self::setDefaultTimezoneFromConfig()) {
$tz = $config->get_cfg_value('timezone');
$tz_delta = date('Z', $stamp);
$tz_delta = $tz_delta / 3600;
return array("name" => $tz, "value" => $tz_delta);
return array('name' => $tz, 'value' => $tz_delta);
} else {
return array('name' => 'unconfigured', 'value' => 0);
}
return $zone;
}
/*
* \brief Get the time zone informations
*
......@@ -76,5 +92,21 @@ class timezone {
{
return DateTimeZone::listIdentifiers();
}
/* \brief Return default timezone as a DateTimeZone object */
static public function getDefaultTimeZone()
{
return new DateTimeZone(date_default_timezone_get());
}
/* \brief Return UTC timezone as a DateTimeZone object */
static public function utc()
{
static $utc;
if (!isset($utc)) {
$utc = new DateTimeZone('UTC');
}
return $utc;
}
}
?>
......@@ -230,8 +230,8 @@ class password extends plugin
$length = $policy['pwdMinLength'][0];
}
if (isset($policy['pwdMinAge'][0]) && isset($attrs['pwdChangedTime'][0])) {
$date = DateTime::createFromFormat('YmdHis\Z', $attrs['pwdChangedTime'][0], new DateTimeZone('UTC'));
$now = new DateTime('now');
$date = DateTime::createFromFormat('YmdHis\Z', $attrs['pwdChangedTime'][0], timezone::utc());
$now = new DateTime('now', timezone::utc());
if ($now->getTimeStamp() < $date->getTimeStamp() + $policy['pwdMinAge'][0]) {
return sprintf(_('You must wait %d seconds before changing your password again'), $policy['pwdMinAge'][0] - ($now->getTimeStamp() - $date->getTimeStamp()));
}
......
......@@ -41,12 +41,12 @@ class EpochDaysDateAttribute extends DateAttribute
protected function ldapToDate($ldapValue)
{
$date = DateTime::createFromFormat('U', $ldapValue * self::$secondsPerDay, new DateTimeZone('UTC'));
$date = DateTime::createFromFormat('U', $ldapValue * self::$secondsPerDay, timezone::utc());
if ($date !== FALSE) {
return $date;
} else {
trigger_error('LDAP value for '.$this->getLdapName().' was not in the right date format.');
return new DateTime($ldapValue, new DateTimeZone('UTC'));
return new DateTime($ldapValue, timezone::utc());
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment