Try a fix when timezone string is not standard

This commit is contained in:
Laurent Destailleur 2014-07-04 13:07:53 +02:00
parent 7ee1388582
commit bf96a78f63
4 changed files with 308 additions and 296 deletions

View File

@ -1,4 +1,4 @@
// Copyright (C) 2011-2012 Laurent Destailleur <eldy@users.sourceforge.net> // Copyright (C) 2011-2014 Laurent Destailleur <eldy@users.sourceforge.net>
// Copyright (C) 2011-2012 Regis Houssin <regis.houssin@capnetworks.com> // Copyright (C) 2011-2012 Regis Houssin <regis.houssin@capnetworks.com>
// //
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
@ -18,7 +18,8 @@
// //
// \file htdocs/core/js/dst.js // \file htdocs/core/js/dst.js
// \brief File that include javascript functions for detect user tz, dst_observed, dst_first, dst_second // \brief File that include javascript functions for detect user tz, tz_string, dst_observed, dst_first, dst_second,
// screenwidth and screenheight
// //
$(document).ready(function () { $(document).ready(function () {
@ -39,7 +40,7 @@ $(document).ready(function () {
dst = "1"; // daylight savings time is observed dst = "1"; // daylight savings time is observed
} }
var now=new Date(); var now=new Date();
var tz=now.toTimeString().match(/\(.*\)/); var tz=now.toTimeString().match(/\(.*\)/); // now.toTimeString may return "12:39:59 GMT+0200 (CEST)"
//alert('date=' + now + ' string=' + now.toTimeString()); //alert('date=' + now + ' string=' + now.toTimeString());
var dst_first=DisplayDstSwitchDates('first'); var dst_first=DisplayDstSwitchDates('first');
var dst_second=DisplayDstSwitchDates('second'); var dst_second=DisplayDstSwitchDates('second');

View File

@ -886,7 +886,7 @@ function dol_print_date($time,$format='',$tzoutput='tzserver',$outputlangs='',$e
if (preg_match('/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i',$time,$reg) if (preg_match('/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i',$time,$reg)
|| preg_match('/^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$/i',$time,$reg)) || preg_match('/^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$/i',$time,$reg))
{ {
// This part of code should not be used. // This part of code should not be used. TODO Remove this.
dol_syslog("Functions.lib::dol_print_date function call with deprecated value of time in page ".$_SERVER["PHP_SELF"], LOG_WARNING); dol_syslog("Functions.lib::dol_print_date function call with deprecated value of time in page ".$_SERVER["PHP_SELF"], LOG_WARNING);
// Date has format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS' or 'YYYYMMDDHHMMSS' // Date has format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS' or 'YYYYMMDDHHMMSS'
$syear = (! empty($reg[1]) ? $reg[1] : ''); $syear = (! empty($reg[1]) ? $reg[1] : '');
@ -904,7 +904,7 @@ function dol_print_date($time,$format='',$tzoutput='tzserver',$outputlangs='',$e
// Date is a timestamps // Date is a timestamps
if ($time < 100000000000) // Protection against bad date values if ($time < 100000000000) // Protection against bad date values
{ {
$ret=adodb_strftime($format,$time+$offsettz+$offsetdst,$to_gmt); $ret=adodb_strftime($format,$time+$offsettz+$offsetdst,$to_gmt); // TODO Remove this
} }
else $ret='Bad value '.$time.' for date'; else $ret='Bad value '.$time.' for date';
} }
@ -912,7 +912,7 @@ function dol_print_date($time,$format='',$tzoutput='tzserver',$outputlangs='',$e
if (preg_match('/__b__/i',$format)) if (preg_match('/__b__/i',$format))
{ {
// Here ret is string in PHP setup language (strftime was used). Now we convert to $outputlangs. // Here ret is string in PHP setup language (strftime was used). Now we convert to $outputlangs.
$month=adodb_strftime('%m',$time+$offsettz+$offsetdst); $month=adodb_strftime('%m',$time+$offsettz+$offsetdst); // TODO Remove this
if ($encodetooutput) if ($encodetooutput)
{ {
$monthtext=$outputlangs->transnoentities('Month'.$month); $monthtext=$outputlangs->transnoentities('Month'.$month);
@ -931,7 +931,7 @@ function dol_print_date($time,$format='',$tzoutput='tzserver',$outputlangs='',$e
} }
if (preg_match('/__a__/i',$format)) if (preg_match('/__a__/i',$format))
{ {
$w=adodb_strftime('%w',$time+$offsettz+$offsetdst); $w=adodb_strftime('%w',$time+$offsettz+$offsetdst); // TODO Remove this
$dayweek=$outputlangs->transnoentitiesnoconv('Day'.$w); $dayweek=$outputlangs->transnoentitiesnoconv('Day'.$w);
$ret=str_replace('__A__',$dayweek,$ret); $ret=str_replace('__A__',$dayweek,$ret);
$ret=str_replace('__a__',dol_substr($dayweek,0,3),$ret); $ret=str_replace('__a__',dol_substr($dayweek,0,3),$ret);
@ -1037,9 +1037,17 @@ function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1)
} }
else if ($gm === 'user') else if ($gm === 'user')
{ {
$default_timezone=(empty($_SESSION["dol_tz_string"])?'UTC':$_SESSION["dol_tz_string"]); // We use dol_tz_string first because it contains dst.
$default_timezone=(empty($_SESSION["dol_tz_string"])?@date_default_timezone_get():$_SESSION["dol_tz_string"]);
try {
$localtz = new DateTimeZone($default_timezone); $localtz = new DateTimeZone($default_timezone);
} }
catch(Exception $e)
{
dol_syslog("Warning dol_tz_string contains an invalid value ".$_SESSION["dol_tz_string"], LOG_WARNING);
$default_timezone=@date_default_timezone_get();
}
}
else $localtz = new DateTimeZone('UTC'); else $localtz = new DateTimeZone('UTC');
$dt = new DateTime(null,$localtz); $dt = new DateTime(null,$localtz);
$dt->setDate($year,$month,$day); $dt->setDate($year,$month,$day);

View File

@ -729,7 +729,7 @@ global $ADODB_DATETIME_CLASS;
} else { } else {
if (isset($TZ)) return $TZ; if (isset($TZ)) return $TZ;
$y = date('Y'); $y = date('Y');
$TZ = mktime(0,0,0,12,2,$y,0) - gmmktime(0,0,0,12,2,$y,0); $TZ = mktime(0,0,0,12,2,$y) - gmmktime(0,0,0,12,2,$y);
} }
return $TZ; return $TZ;

View File

@ -447,6 +447,9 @@ if (! defined('NOLOGIN'))
$dol_authmode=$conf->authmode; // This properties is defined only when logged, to say what mode was successfully used $dol_authmode=$conf->authmode; // This properties is defined only when logged, to say what mode was successfully used
$dol_tz=$_POST["tz"]; $dol_tz=$_POST["tz"];
$dol_tz_string=$_POST["tz_string"]; $dol_tz_string=$_POST["tz_string"];
$dol_tz_string=preg_replace('\s*\(.+\)$','',$dol_tz_string);
$dol_tz_string=preg_replace(',','/',$dol_tz_string);
$dol_tz_string=preg_replace('\s','_',$dol_tz_string);
$dol_dst=0; $dol_dst=0;
if (isset($_POST["dst_first"]) && isset($_POST["dst_second"])) if (isset($_POST["dst_first"]) && isset($_POST["dst_second"]))
{ {