Add more test to prepare option for rounding lines

This commit is contained in:
Laurent Destailleur 2012-02-06 00:07:48 +01:00
parent 2093b3f0be
commit 7b527e085d
8 changed files with 47 additions and 28 deletions

View File

@ -159,7 +159,7 @@ $var=!$var;
print '<tr '.$bc[$var].'><td width="300">'.$langs->trans("CurrentTimeZone").'</td><td>'; // Timezone server PHP
$a=getCurrentTimeZoneString();
$a.=' '.getCurrentTimeZoneInt();
$a.=' ('.(-dol_mktime(0,0,0,1,1,1970)>0?'+':'').(-dol_mktime(0,0,0,1,1,1970)).')';
$a.=' ('.(getCurrentTimeZoneInt()>0?'+':'').(getCurrentTimeZoneInt()*3600).')';
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
$var=!$var;
@ -203,4 +203,6 @@ print '</table>';
print '<br>';
llxFooter();
$db->close();
?>

View File

@ -86,7 +86,6 @@ class Conf
$this->user=(object) array();
//! Charset for HTML output and for storing data in memory
$this->file->character_set_client='UTF-8'; // UTF-8, ISO-8859-1
$this->global->MAIN_OLD_DATE=1;
}

View File

@ -76,14 +76,14 @@ function getCurrentTimeZoneString()
/**
* Return server timezone int.
* If $conf->global->MAIN_OLD_DATE is set, we use old behaviour: All convertion does not include daylight.
* If $conf->global->MAIN_NEW_DATE is set, we use new behaviour: All convertions take care of dayling saving time.
*
* @return string An offset in seconds (3600 for Europe/Paris on winter and 7200 for Europe/Paris on summer)
*/
function getCurrentTimeZoneInt()
{
global $conf;
if (class_exists('DateTime') && empty($conf->global->MAIN_OLD_DATE))
if (class_exists('DateTime') && ! empty($conf->global->MAIN_NEW_DATE))
{
// Method 1 (include daylight)
$localtz = new DateTimeZone(date_default_timezone_get());

View File

@ -1047,6 +1047,7 @@ function dolibarr_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$chec
*/
function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1)
{
global $conf;
//print "- ".$hour.",".$minute.",".$second.",".$month.",".$day.",".$year.",".$_SERVER["WINDIR"]." -";
// Clean parameters
@ -1065,26 +1066,29 @@ function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1)
if ($second< 0 || $second > 60) return '';
}
$usealternatemethod=false;
if ($year <= 1970) $usealternatemethod=true; // <= 1970
if ($year >= 2038) $usealternatemethod=true; // >= 2038
if ($usealternatemethod || $gm) // Si time gm, seule adodb peut convertir
if (class_exists('DateTime') && ! empty($conf->global->MAIN_NEW_DATE))
{
/*
// On peut utiliser strtotime pour obtenir la traduction.
// strtotime is ok for range: Friday 13 December 1901 20:45:54 GMT to Tuesday 19 January 2038 03:14:07 GMT.
$montharray=array(1=>'january',2=>'february',3=>'march',4=>'april',5=>'may',6=>'june',
7=>'july',8=>'august',9=>'september',10=>'october',11=>'november',12=>'december');
$string=$day." ".$montharray[0+$month]." ".$year." ".$hour.":".$minute.":".$second." GMT";
$date=strtotime($string);
print "- ".$string." ".$date." -";
*/
$date=adodb_mktime($hour,$minute,$second,$month,$day,$year,$isdst,$gm);
if (empty($gm)) $localtz = new DateTimeZone(date_default_timezone_get());
else $localtz = new DateTimeZone('UTC');
$dt = new DateTime(null,$localtz);
$dt->setDate($year,$month,$day);
$dt->setTime($hour,$minute,$second);
$date=$dt->getTimestamp();
}
else
{
$date=mktime($hour,$minute,$second,$month,$day,$year);
$usealternatemethod=false;
if ($year <= 1970) $usealternatemethod=true; // <= 1970
if ($year >= 2038) $usealternatemethod=true; // >= 2038
if ($usealternatemethod || $gm) // Si time gm, seule adodb peut convertir
{
$date=adodb_mktime($hour,$minute,$second,$month,$day,$year,$isdst,$gm);
}
else
{
$date=mktime($hour,$minute,$second,$month,$day,$year);
}
}
return $date;
}

View File

@ -204,7 +204,7 @@ if (! defined('DOL_DEFAULT_TTF_BOLD')) { define('DOL_DEFAULT_TTF_BOLD', (!isset(
* Include functions
*/
if (! defined('ADODB_DATE_VERSION')) include_once(ADODB_PATH.'adodb-time.inc.php');
if (! defined('ADODB_DATE_VERSION')) include_once(ADODB_PATH.'adodb-time.inc.php');
if (! file_exists(DOL_DOCUMENT_ROOT ."/core/lib/functions.lib.php"))
{

View File

@ -1,7 +1,7 @@
<?PHP
/* Copyright (C) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Xavier Dutoit <doli@sydesy.com>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
@ -75,8 +75,7 @@ if (! empty($dolibarr_main_document_root_alt))
}
// Force db type (for test purpose)
if (defined('TEST_DB_FORCE_TYPE')) $conf->db->type=constant('TEST_DB_FORCE_TYPE');
// Multi-Company transverse mode
// Force Multi-Company transverse mode
$conf->multicompany->transverse_mode = empty($multicompany_transverse_mode)?'':$multicompany_transverse_mode;
// Chargement des includes principaux de librairies communes

View File

@ -91,8 +91,11 @@ class FunctionsTest extends PHPUnit_Framework_TestCase
print __METHOD__."\n";
}
/**
*/
/**
* Init phpunit tests
*
* @return void
*/
protected function setUp()
{
global $conf,$user,$langs,$db;
@ -103,8 +106,11 @@ class FunctionsTest extends PHPUnit_Framework_TestCase
print __METHOD__."\n";
}
/**
*/
/**
* End phpunit tests
*
* @return void
*/
protected function tearDown()
{
print __METHOD__."\n";
@ -222,6 +228,9 @@ class FunctionsTest extends PHPUnit_Framework_TestCase
}
/**
* testDolMkTime
*
* @return void
*/
public function testDolMkTime()
{

View File

@ -89,6 +89,9 @@ class PropalTest extends PHPUnit_Framework_TestCase
}
/**
* Init phpunit tests
*
* @return void
*/
protected function setUp()
{
@ -102,6 +105,9 @@ class PropalTest extends PHPUnit_Framework_TestCase
//print $db->getVersion()."\n";
}
/**
* End phpunit tests
*
* @return void
*/
protected function tearDown()
{