2
0
forked from Wavyzz/dolibarr

Fix: DST is correctly detected

This commit is contained in:
Laurent Destailleur
2011-11-01 04:57:45 +01:00
parent 8c42f48ad7
commit ecb6c1e67d
7 changed files with 193 additions and 42 deletions

View File

@@ -141,17 +141,17 @@ $dec=$langs->trans("SeparatorDecimal");
print '<tr '.$bc[$var].'><td width="300">'.$langs->trans("CurrentValueSeparatorDecimal").'</td><td>'.$dec.'</td></tr>'."\n"; print '<tr '.$bc[$var].'><td width="300">'.$langs->trans("CurrentValueSeparatorDecimal").'</td><td>'.$dec.'</td></tr>'."\n";
// Show results of functions to see if everything works // Show results of functions to see if everything works
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td width="300">=> price2num(1233.56+1)</td><td>'.price2num(1233.56+1,'2').'</td></tr>'; print '<tr '.$bc[$var].'><td width="300">&nbsp; => price2num(1233.56+1)</td><td>'.price2num(1233.56+1,'2').'</td></tr>';
$var=!$var; $var=!$var;
print "<tr ".$bc[$var].'><td width=\"300\">=> price2num('."'1".$thousand."234".$dec."56')</td><td>".price2num("1".$thousand."234".$dec."56",'2')."</td>"; print "<tr ".$bc[$var].'><td width=\"300\">&nbsp; => price2num('."'1".$thousand."234".$dec."56')</td><td>".price2num("1".$thousand."234".$dec."56",'2')."</td>";
if (($thousand != ',' && $thousand != '.') || ($thousand != ' ')) if (($thousand != ',' && $thousand != '.') || ($thousand != ' '))
{ {
$var=!$var; $var=!$var;
print "<tr ".$bc[$var].'><td width=\"300\">=> price2num('."'1 234.56')</td><td>".price2num("1 234.56",'2')."</td>"; print "<tr ".$bc[$var].'><td width=\"300\">&nbsp; => price2num('."'1 234.56')</td><td>".price2num("1 234.56",'2')."</td>";
print "</tr>\n"; print "</tr>\n";
} }
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td width="300">=> price(1234.56)</td><td>'.price(1234.56).'</td>'; print '<tr '.$bc[$var].'><td width="300">&nbsp; => price(1234.56)</td><td>'.price(1234.56).'</td>';
// Timezone // Timezone
$txt =$langs->trans("OSTZ").' (variable system TZ): '.($_ENV["TZ"]?$_ENV["TZ"]:$langs->trans("NotDefined")).'<br>'."\n"; $txt =$langs->trans("OSTZ").' (variable system TZ): '.($_ENV["TZ"]?$_ENV["TZ"]:$langs->trans("NotDefined")).'<br>'."\n";
$txt.=$langs->trans("PHPTZ").' (php.ini date.timezone): '.(ini_get("date.timezone")?ini_get("date.timezone"):$langs->trans("NotDefined")).''."\n"; // date.timezone must be in valued defined in http://fr3.php.net/manual/en/timezones.europe.php $txt.=$langs->trans("PHPTZ").' (php.ini date.timezone): '.(ini_get("date.timezone")?ini_get("date.timezone"):$langs->trans("NotDefined")).''."\n"; // date.timezone must be in valued defined in http://fr3.php.net/manual/en/timezones.europe.php
@@ -160,6 +160,7 @@ if (function_exists('date_default_timezone_get'))
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td width="300">'.$langs->trans("CurrentTimeZone").'</td><td>'; // Timezone server PHP print '<tr '.$bc[$var].'><td width="300">'.$langs->trans("CurrentTimeZone").'</td><td>'; // Timezone server PHP
$a=date_default_timezone_get(); $a=date_default_timezone_get();
$a.=' '.getCurrentTimeZone();
$a.=' ('.(-dol_mktime(0,0,0,1,1,1970)>0?'+':'').(-dol_mktime(0,0,0,1,1,1970)).')'; $a.=' ('.(-dol_mktime(0,0,0,1,1,1970)>0?'+':'').(-dol_mktime(0,0,0,1,1,1970)).')';
print $form->textwithtooltip($a,$txt,2,1,img_info('')); print $form->textwithtooltip($a,$txt,2,1,img_info(''));
print '</td></tr>'."\n"; // value defined in http://fr3.php.net/manual/en/timezones.europe.php print '</td></tr>'."\n"; // value defined in http://fr3.php.net/manual/en/timezones.europe.php
@@ -173,27 +174,34 @@ else
print '</td></tr>'."\n"; print '</td></tr>'."\n";
} }
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td width="300">=> '.$langs->trans("CurrentHour").'</td><td>'.dol_print_date(dol_now(),'dayhour','tzserver').'</td></tr>'."\n"; print '<tr '.$bc[$var].'><td width="300">&nbsp; => '.$langs->trans("CurrentHour").'</td><td>'.dol_print_date(dol_now(),'dayhour','tzserver').'</td></tr>'."\n";
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td width="300">=> dol_print_date(0,"dayhourtext")</td><td>'.dol_print_date(0,"dayhourtext").'</td>'; print '<tr '.$bc[$var].'><td width="300">&nbsp; => dol_print_date(0,"dayhourtext")</td><td>'.dol_print_date(0,"dayhourtext").'</td>';
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td width="300">=> dol_get_first_day(1970,1,false)</td><td>'.dol_get_first_day(1970,1,false).' &nbsp; &nbsp; (=> dol_print_date() or idate() of this value = '.dol_print_date(dol_get_first_day(1970,1,false),'dayhour').')</td>'; print '<tr '.$bc[$var].'><td width="300">&nbsp; => dol_get_first_day(1970,1,false)</td><td>'.dol_get_first_day(1970,1,false).' &nbsp; &nbsp; (=> dol_print_date() or idate() of this value = '.dol_print_date(dol_get_first_day(1970,1,false),'dayhour').')</td>';
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td width="300">=> dol_get_first_day(1970,1,true)</td><td>'.dol_get_first_day(1970,1,true).' &nbsp; &nbsp; (=> dol_print_date() or idate() of this value = '.dol_print_date(dol_get_first_day(1970,1,true),'dayhour').')</td>'; print '<tr '.$bc[$var].'><td width="300">&nbsp; => dol_get_first_day(1970,1,true)</td><td>'.dol_get_first_day(1970,1,true).' &nbsp; &nbsp; (=> dol_print_date() or idate() of this value = '.dol_print_date(dol_get_first_day(1970,1,true),'dayhour').')</td>';
// Parent company // Parent company
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td width="300">'.$langs->trans("CompanyTZ").'</td><td>'.$langs->trans("FeatureNotYetAvailable").'</td></tr>'."\n"; print '<tr '.$bc[$var].'><td width="300">'.$langs->trans("CompanyTZ").'</td><td>'.$langs->trans("FeatureNotYetAvailable").'</td></tr>'."\n";
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td width="300">=> '.$langs->trans("CompanyHour").'</td><td>'.$langs->trans("FeatureNotYetAvailable").'</td></tr>'."\n"; print '<tr '.$bc[$var].'><td width="300">&nbsp; => '.$langs->trans("CompanyHour").'</td><td>'.$langs->trans("FeatureNotYetAvailable").'</td></tr>'."\n";
// Client // Client
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td width="300">'.$langs->trans("ClientTZ").'</td><td>'.($_SESSION['dol_tz']!=''?($_SESSION['dol_tz']>=0?'+':'').$_SESSION['dol_tz']:'').' ('.($_SESSION['dol_tz']>=0?'+':'').($_SESSION['dol_tz']*60*60).')</td></tr>'."\n"; print '<tr '.$bc[$var].'><td width="300">'.$langs->trans("ClientTZ").'</td><td>'.($_SESSION['dol_tz']!=''?($_SESSION['dol_tz']>=0?'+':'').$_SESSION['dol_tz']:'').' ('.($_SESSION['dol_tz']>=0?'+':'').($_SESSION['dol_tz']*60*60).')</td></tr>'."\n";
//$var=!$var; //$var=!$var;
//print '<tr '.$bc[$var].'><td width="300">=> '.$langs->trans("ClientOffsetWithGreenwich").'</td><td>'..'</td></tr>'."\n"; //print '<tr '.$bc[$var].'><td width="300">&nbsp; => '.$langs->trans("ClientOffsetWithGreenwich").'</td><td>'..'</td></tr>'."\n";
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td width="300">'.$langs->trans("DaylingSavingTime").'</td><td>'.($_SESSION['dol_dst']>=0?yn(1):yn(0)).' ('.($_SESSION['dol_dst']>=0?'+':'').($_SESSION['dol_dst']*60*60).')</td></tr>'."\n"; print '<tr '.$bc[$var].'><td width="300">'.$langs->trans("DaylingSavingTime").'</td><td>';
if ($_SESSION['dol_dst']>0)
{
print ($_SESSION['dol_dst']>0?'+':'').($_SESSION['dol_dst']).' ('.($_SESSION['dol_dst']>0?'+':'').($_SESSION['dol_dst']*60*60).')';
}
else print yn(0);
if (isset($_SESSION['dol_dst_first'])) print ' &nbsp; &nbsp; ('.dol_print_date(dol_stringtotime($_SESSION['dol_dst_first']),'dayhour','gmt').' - '.dol_print_date(dol_stringtotime($_SESSION['dol_dst_second']),'dayhour','gmt').')';
print '</td></tr>'."\n";
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td width="300">=> '.$langs->trans("ClientHour").'</td><td>'.dol_print_date(dol_now(),'dayhour','tzuser').'</td></tr>'."\n"; print '<tr '.$bc[$var].'><td width="300">&nbsp; => '.$langs->trans("ClientHour").'</td><td>'.dol_print_date(dol_now(),'dayhour','tzuser').'</td></tr>'."\n";
$var=!$var; $var=!$var;
$filesystemencoding=ini_get("unicode.filesystem_encoding"); // Disponible avec PHP 6.0 $filesystemencoding=ini_get("unicode.filesystem_encoding"); // Disponible avec PHP 6.0
@@ -204,7 +212,7 @@ $tmp=ini_get("unicode.filesystem_encoding"); // Disponible avec PHP 6.0
if (empty($tmp) && ! empty($_SERVER["WINDIR"])) $tmp='iso-8859-1'; // By default for windows if (empty($tmp) && ! empty($_SERVER["WINDIR"])) $tmp='iso-8859-1'; // By default for windows
if (empty($tmp)) $tmp='utf-8'; // By default for other if (empty($tmp)) $tmp='utf-8'; // By default for other
if (! empty($conf->global->MAIN_FILESYSTEM_ENCODING)) $tmp=$conf->global->MAIN_FILESYSTEM_ENCODING; if (! empty($conf->global->MAIN_FILESYSTEM_ENCODING)) $tmp=$conf->global->MAIN_FILESYSTEM_ENCODING;
print '<tr '.$bc[$var].'><td width="300">=> '.$langs->trans("File encoding").'</td><td>'.$tmp.'</td></tr>'."\n"; // date.timezone must be in valued defined in http://fr3.php.net/manual/en/timezones.europe.php print '<tr '.$bc[$var].'><td width="300">&nbsp; => '.$langs->trans("File encoding").'</td><td>'.$tmp.'</td></tr>'."\n"; // date.timezone must be in valued defined in http://fr3.php.net/manual/en/timezones.europe.php
print '</table>'; print '</table>';
print '<br>'; print '<br>';

View File

@@ -553,7 +553,6 @@ if (count($listofextcals))
$event->id=$icalevent['UID']; $event->id=$icalevent['UID'];
$event->icalname=$namecal; $event->icalname=$namecal;
$event->icalcolor=$colorcal; $event->icalcolor=$colorcal;
//$usertime=($_SESSION['dol_tz']*60*60)+($_SESSION['dol_dst']*60*60);
$usertime=0; // We dont modify date because we want to have date into memory datep and datef stored as GMT date. Compensation will be done during output. $usertime=0; // We dont modify date because we want to have date into memory datep and datef stored as GMT date. Compensation will be done during output.
$event->datep=$datestart+$usertime; $event->datep=$datestart+$usertime;
$event->datef=$dateend+$usertime; $event->datef=$dateend+$usertime;

View File

@@ -61,6 +61,23 @@ function get_tz_array()
} }
/**
* Return server timezone
*
* @return string TimeZone
*/
function getCurrentTimeZone()
{
// Method 1
//$tzstring=date_default_timezone_get(); // Then convert into tz
// Method 2
$tmp=dol_mktime(0,0,0,1,1,1970);
$tz=($tmp<0?'+':'-').sprintf("%02d",abs($tmp/3600));
return $tz;
}
/** /**
* Add a delay to a date * Add a delay to a date
* *

View File

@@ -828,8 +828,8 @@ function dol_print_date($time,$format='',$tzoutput='tzserver',$outputlangs='',$e
* YYYY-MM-DDTHH:MM:SSZ (RFC3339) * YYYY-MM-DDTHH:MM:SSZ (RFC3339)
* DD/MM/YY or DD/MM/YYYY (this format should not be used anymore) * DD/MM/YY or DD/MM/YYYY (this format should not be used anymore)
* DD/MM/YY HH:MM:SS or DD/MM/YYYY HH:MM:SS (this format should not be used anymore) * DD/MM/YY HH:MM:SS or DD/MM/YYYY HH:MM:SS (this format should not be used anymore)
* 19700101020000 -> 7200
* @param int $gm 1=Input date is GM date, 0=Input date is local date * @param int $gm 1=Input date is GM date, 0=Input date is local date
* 19700101020000 -> 7200 with gm=1
* @return date Date * @return date Date
* *
* @see dol_print_date, dol_mktime, dol_getdate * @see dol_print_date, dol_mktime, dol_getdate

View File

@@ -55,7 +55,113 @@ header("Content-type: text/html; charset=".$conf->file->character_set_client);
<body class="body"> <body class="body">
<!-- Javascript code on logon page only to detect user tz, dst_observed, dst_first, dst_second -->
<script type="text/javascript"> <script type="text/javascript">
function DisplayDstSwitchDates(firstsecond)
{
var year = new Date().getYear();
if (year < 1000) year += 1900;
var firstSwitch = 0;
var secondSwitch = 0;
var lastOffset = 99;
// Loop through every month of the current year
for (i = 0; i < 12; i++)
{
// Fetch the timezone value for the month
var newDate = new Date(Date.UTC(year, i, 0, 0, 0, 0, 0));
var tz = -1 * newDate.getTimezoneOffset() / 60;
// Capture when a timzezone change occurs
if (tz > lastOffset)
firstSwitch = i-1;
else if (tz < lastOffset)
secondSwitch = i-1;
lastOffset = tz;
}
// Go figure out date/time occurences a minute before
// a DST adjustment occurs
var secondDstDate = FindDstSwitchDate(year, secondSwitch);
var firstDstDate = FindDstSwitchDate(year, firstSwitch);
if (firstsecond == 'first') return firstDstDate;
if (firstsecond == 'second') return secondDstDate;
if (firstDstDate == null && secondDstDate == null)
return 'Daylight Savings is not observed in your timezone.';
else
return 'Last minute before DST change occurs in ' +
year + ': ' + firstDstDate + ' and ' + secondDstDate;
}
function FindDstSwitchDate(year, month)
{
// Set the starting date
var baseDate = new Date(Date.UTC(year, month, 0, 0, 0, 0, 0));
var changeDay = 0;
var changeMinute = -1;
var baseOffset = -1 * baseDate.getTimezoneOffset() / 60;
var dstDate;
// Loop to find the exact day a timezone adjust occurs
for (day = 0; day < 50; day++)
{
var tmpDate = new Date(Date.UTC(year, month, day, 0, 0, 0, 0));
var tmpOffset = -1 * tmpDate.getTimezoneOffset() / 60;
// Check if the timezone changed from one day to the next
if (tmpOffset != baseOffset)
{
var minutes = 0;
changeDay = day;
// Back-up one day and grap the offset
tmpDate = new Date(Date.UTC(year, month, day-1, 0, 0, 0, 0));
tmpOffset = -1 * tmpDate.getTimezoneOffset() / 60;
// Count the minutes until a timezone chnage occurs
while (changeMinute == -1)
{
tmpDate = new Date(Date.UTC(year, month, day-1, 0, minutes, 0, 0));
tmpOffset = -1 * tmpDate.getTimezoneOffset() / 60;
// Determine the exact minute a timezone change
// occurs
if (tmpOffset != baseOffset)
{
// Back-up a minute to get the date/time just
// before a timezone change occurs
tmpOffset = new Date(Date.UTC(year, month,
day-1, 0, minutes-1, 0, 0));
changeMinute = minutes;
break;
}
else
minutes++;
}
// Add a month (for display) since JavaScript counts
// months from 0 to 11
dstDate = tmpOffset.getMonth() + 1;
// Pad the month as needed
if (dstDate < 10) dstDate = "0" + dstDate;
// Add the day and year
dstDate = year + '-' + dstDate + '-' + tmpOffset.getDate() + 'T';
// Capture the time stamp
tmpDate = new Date(Date.UTC(year, month,
day-1, 0, minutes-1, 0, 0));
dstDate += tmpDate.toTimeString().split(' ')[0] + 'Z';
return dstDate;
}
}
}
jQuery(document).ready(function () { jQuery(document).ready(function () {
// Set focus on correct field // Set focus on correct field
<?php if ($focus_element) { ?>jQuery('#<?php echo $focus_element; ?>').focus(); <?php } ?> // Warning to use this only on visible element <?php if ($focus_element) { ?>jQuery('#<?php echo $focus_element; ?>').focus(); <?php } ?> // Warning to use this only on visible element
@@ -75,8 +181,13 @@ jQuery(document).ready(function () {
} else { } else {
dst = "1"; // daylight savings time is observed dst = "1"; // daylight savings time is observed
} }
var dst_first=DisplayDstSwitchDates('first');
var dst_second=DisplayDstSwitchDates('second');
//alert(dst);
jQuery('#tz').val(std_time_offset); // returns TZ jQuery('#tz').val(std_time_offset); // returns TZ
jQuery('#dst').val(dst); // returns DST jQuery('#dst_observed').val(dst); // returns if DST is observed on summer
jQuery('#dst_first').val(dst_first); // returns DST first switch in year
jQuery('#dst_second').val(dst_second); // returns DST second switch in year
// Detect and save screen resolution // Detect and save screen resolution
jQuery('#screenwidth').val(jQuery(window).width()); // returns width of browser viewport jQuery('#screenwidth').val(jQuery(window).width()); // returns width of browser viewport
jQuery('#screenheight').val(jQuery(window).height()); // returns width of browser viewport jQuery('#screenheight').val(jQuery(window).height()); // returns width of browser viewport
@@ -88,7 +199,9 @@ jQuery(document).ready(function () {
<input type="hidden" name="loginfunction" value="loginfunction" /> <input type="hidden" name="loginfunction" value="loginfunction" />
<!-- Add fields to send local user information --> <!-- Add fields to send local user information -->
<input type="hidden" name="tz" id="tz" value="" /> <input type="hidden" name="tz" id="tz" value="" />
<input type="hidden" name="dst" id="dst" value="" /> <input type="hidden" name="dst_observed" id="dst_observed" value="" />
<input type="hidden" name="dst_first" id="dst_first" value="" />
<input type="hidden" name="dst_second" id="dst_second" value="" />
<input type="hidden" name="screenwidth" id="screenwidth" value="" /> <input type="hidden" name="screenwidth" id="screenwidth" value="" />
<input type="hidden" name="screenheight" id="screenheight" value="" /> <input type="hidden" name="screenheight" id="screenheight" value="" />

View File

@@ -381,7 +381,18 @@ 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_dst=$_POST["dst"]; $dol_dst=0;
if (isset($_POST["dst_first"]) && isset($_POST["dst_second"]))
{
$datenow=dol_now();
$datefirst=dol_stringtotime($_POST["dst_first"]);
$datesecond=dol_stringtotime($_POST["dst_second"]);
if ($datenow >= $datefirst && $datenow < $datesecond) $dol_dst=1;
}
//print $datefirst.'-'.$datesecond.'-'.$datenow; exit;
$dol_dst_observed=$_POST["dst_observed"];
$dol_dst_first=$_POST["dst_first"];
$dol_dst_second=$_POST["dst_second"];
$dol_screenwidth=$_POST["screenwidth"]; $dol_screenwidth=$_POST["screenwidth"];
$dol_screenheight=$_POST["screenheight"]; $dol_screenheight=$_POST["screenheight"];
} }
@@ -515,6 +526,9 @@ if (! defined('NOLOGIN'))
$_SESSION["dol_authmode"]=isset($dol_authmode)?$dol_authmode:''; $_SESSION["dol_authmode"]=isset($dol_authmode)?$dol_authmode:'';
$_SESSION["dol_tz"]=isset($dol_tz)?$dol_tz:''; $_SESSION["dol_tz"]=isset($dol_tz)?$dol_tz:'';
$_SESSION["dol_dst"]=isset($dol_dst)?$dol_dst:''; $_SESSION["dol_dst"]=isset($dol_dst)?$dol_dst:'';
$_SESSION["dol_dst_observed"]=isset($dol_dst_observed)?$dol_dst_observed:'';
$_SESSION["dol_dst_first"]=isset($dol_dst_first)?$dol_dst_first:'';
$_SESSION["dol_dst_second"]=isset($dol_dst_second)?$dol_dst_second:'';
$_SESSION["dol_screenwidth"]=isset($dol_screenwidth)?$dol_screenwidth:''; $_SESSION["dol_screenwidth"]=isset($dol_screenwidth)?$dol_screenwidth:'';
$_SESSION["dol_screenheight"]=isset($dol_screenheight)?$dol_screenheight:''; $_SESSION["dol_screenheight"]=isset($dol_screenheight)?$dol_screenheight:'';
$_SESSION["dol_company"]=$conf->global->MAIN_INFO_SOCIETE_NOM; $_SESSION["dol_company"]=$conf->global->MAIN_INFO_SOCIETE_NOM;