Try a fix when timezone string is not standard

Conflicts:
	htdocs/includes/adodbtime/adodb-time.inc.php
This commit is contained in:
Laurent Destailleur 2014-07-04 13:07:53 +02:00 committed by Laurent Destailleur
parent 863d57004e
commit 6a61587085
3 changed files with 30 additions and 18 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,22 +40,22 @@ $(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');
//alert(dst); //alert(dst);
$('#tz').val(std_time_offset); // returns TZ $('#tz').val(std_time_offset); // returns TZ
// tz is null with IE // tz is null with IE
if (tz != null) { if (tz != null) {
$('#tz_string').val(tz[0].replace('(','').replace(')','')); // returns TZ string $('#tz_string').val(tz[0].replace('(','').replace(')','')); // returns TZ string
} }
$('#dst_observed').val(dst); // returns if DST is observed on summer $('#dst_observed').val(dst); // returns if DST is observed on summer
$('#dst_first').val(dst_first); // returns DST first switch in year $('#dst_first').val(dst_first); // returns DST first switch in year
$('#dst_second').val(dst_second); // returns DST second switch in year $('#dst_second').val(dst_second); // returns DST second switch in year
// Detect and save screen resolution // Detect and save screen resolution
$('#screenwidth').val($(window).width()); // returns width of browser viewport $('#screenwidth').val($(window).width()); // returns width of browser viewport
$('#screenheight').val($(window).height()); // returns width of browser viewport $('#screenheight').val($(window).height()); // returns width of browser viewport
}); });
function DisplayDstSwitchDates(firstsecond) function DisplayDstSwitchDates(firstsecond)

View File

@ -871,7 +871,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] : '');
@ -889,7 +889,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';
} }
@ -897,7 +897,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);
@ -916,7 +916,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);
@ -1029,8 +1029,16 @@ 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.
$localtz = new DateTimeZone($default_timezone); $default_timezone=(empty($_SESSION["dol_tz_string"])?@date_default_timezone_get():$_SESSION["dol_tz_string"]);
try {
$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);
@ -4533,4 +4541,4 @@ function natural_search($fields, $value)
return " AND " . ($end > 1? '(' : '') . $res; return " AND " . ($end > 1? '(' : '') . $res;
} }
?> ?>

View File

@ -446,6 +446,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"]))
{ {
@ -1880,4 +1883,4 @@ if (! function_exists("llxFooter"))
} }
} }
?> ?>