#359 Dehardcoded the timezone (while preserving 'Europe/Paris' as the default)

SVN:trunk[1177]
This commit is contained in:
Romain Quetiez
2011-04-05 12:22:38 +00:00
parent 446a8f74fb
commit 25c529a797
4 changed files with 44 additions and 27 deletions

View File

@@ -1823,20 +1823,6 @@ class AttributeEnum extends AttributeString
*/
class AttributeDateTime extends AttributeDBField
{
//const MYDATETIMEZONE = "UTC";
const MYDATETIMEZONE = "Europe/Paris";
static protected $const_TIMEZONE = null; // set once for all upon object construct
static public function InitStatics()
{
// Init static constant once for all (remove when PHP allows real static const)
self::$const_TIMEZONE = new DateTimeZone(self::MYDATETIMEZONE);
// #@# Init default timezone -> do not get a notice... to be improved !!!
// duplicated in the email test page (the mail function does trigger a notice as well)
date_default_timezone_set(self::MYDATETIMEZONE);
}
static protected function GetDateFormat()
{
return "Y-m-d H:i:s";
@@ -1852,10 +1838,9 @@ class AttributeDateTime extends AttributeDBField
protected function GetSQLCol() {return "TIMESTAMP";}
public static function GetAsUnixSeconds($value)
{
$oDeadlineDateTime = new DateTime($value, self::$const_TIMEZONE);
$oDeadlineDateTime = new DateTime($value);
$iUnixSeconds = $oDeadlineDateTime->format('U');
return $iUnixSeconds;
}
// #@# THIS HAS TO REVISED
@@ -2153,11 +2138,6 @@ class AttributeDate extends AttributeDateTime
return "Y-m-d";
}
static public function InitStatics()
{
// Nothing to do...
}
static protected function ListExpectedParams()
{
return parent::ListExpectedParams();
@@ -2173,9 +2153,6 @@ class AttributeDate extends AttributeDateTime
}
}
// Init static constant once for all (remove when PHP allows real static const)
AttributeDate::InitStatics();
/**
* A dead line stored as a date & time
* The only difference with the DateTime attribute is the display:
@@ -2233,9 +2210,6 @@ class AttributeDeadline extends AttributeDateTime
return $sResult;
}
}
// Init static constant once for all (remove when PHP allows real static const)
AttributeDateTime::InitStatics();
/**
* Map a foreign key to an attribute

View File

@@ -84,6 +84,17 @@ class CMDBSource
}
}
public static function SetTimezone($sTimezone = null)
{
// Note: requires the installation of MySQL special tables,
// otherwise, only 'SYSTEM' or "+10:00' may be specified which is NOT sufficient because of day light saving times
if (!is_null($sTimezone))
{
$sQuotedTimezone = self::Quote($sTimezone);
self::Query("SET time_zone = $sQuotedTimezone");
}
}
public static function ListDB()
{
$aDBs = self::QueryToCol('SHOW DATABASES', 'Database');

View File

@@ -286,6 +286,24 @@ class Config
'source_of_value' => '',
'show_in_conf_sample' => true,
),
'apc_cache.query_ttl' => array(
'type' => 'integer',
'description' => 'Time to live set in APC for the prepared queries (seconds - 0 means no timeout)',
'default' => 3600,
'value' => 3600,
'source_of_value' => '',
'show_in_conf_sample' => true,
),
'timezone' => array(
'type' => 'string',
'description' => 'Timezone (reference: http://php.net/manual/en/timezones.php). If empty, it will be left unchanged and MUST be explicitely configured in PHP',
// examples... not used (nor 'description')
'examples' => array('America/Sao_Paulo', 'America/New_York (standing for EDT)', 'America/Los_Angeles (standing for PDT)', 'Asia/Istanbul', 'Asia/Singapore', 'Africa/Casablanca', 'Australia/Sydney'),
'default' => 'Europe/Paris',
'value' => 'Europe/Paris',
'source_of_value' => '',
'show_in_conf_sample' => true,
),
);
public function IsProperty($sPropCode)

View File

@@ -3628,6 +3628,19 @@ abstract class MetaModel
&& function_exists('apc_store');
self::$m_iQueryCacheTTL = self::$m_oConfig->Get('apc_cache.query_ttl');
// PHP timezone first...
//
$sPHPTimezone = self::$m_oConfig->Get('timezone');
if ($sPHPTimezone == '')
{
// Leave as is... up to the admin to set a value somewhere...
//$sPHPTimezone = date_default_timezone_get();
}
else
{
date_default_timezone_set($sPHPTimezone);
}
// Note: load the dictionary as soon as possible, because it might be
// needed when some error occur
$sAppIdentity = self::GetConfig()->Get('session_name');
@@ -3750,6 +3763,7 @@ abstract class MetaModel
CMDBSource::Init($sServer, $sUser, $sPwd); // do not select the DB (could not exist)
CMDBSource::SetCharacterSet($sCharacterSet, $sCollation);
// Later when timezone implementation is correctly done: CMDBSource::SetTimezone($sDBTimezone);
}
public static function GetModuleSetting($sModule, $sProperty, $defaultvalue = null)