Example #1
0
/**
 * Return server timezone int.
 *
 * @param	string	$refgmtdate		Reference period for timezone (timezone differs on winter and summer. May be 'now', 'winter' or 'summer')
 * @return 	int						An offset in hour (+1 for Europe/Paris on winter and +2 for Europe/Paris on summer)
 */
function getServerTimeZoneInt($refgmtdate = 'now')
{
    global $conf;
    if (method_exists('DateTimeZone', 'getOffset')) {
        // Method 1 (include daylight)
        $gmtnow = dol_now('gmt');
        $yearref = dol_print_date($gmtnow, '%Y');
        $monthref = dol_print_date($gmtnow, '%m');
        $dayref = dol_print_date($gmtnow, '%d');
        if ($refgmtdate == 'now') {
            $newrefgmtdate = $yearref . '-' . $monthref . '-' . $dayref;
        } elseif ($refgmtdate == 'summer') {
            $newrefgmtdate = $yearref . '-08-01';
        } else {
            $newrefgmtdate = $yearref . '-01-01';
        }
        $newrefgmtdate .= 'T00:00:00+00:00';
        $localtz = new DateTimeZone(getServerTimeZoneString());
        $localdt = new DateTime($newrefgmtdate, $localtz);
        $tmp = -1 * $localtz->getOffset($localdt);
        //print $refgmtdate.'='.$tmp;
    } else {
        $tmp = 0;
        dol_print_error('', 'PHP version must be 5.3+');
    }
    $tz = round(($tmp < 0 ? 1 : -1) * abs($tmp / 3600));
    return $tz;
}
 public static function setUpBeforeClass()
 {
     global $conf, $user, $langs, $db;
     if (getServerTimeZoneString() != 'Europe/Paris') {
         print "\n" . __METHOD__ . " This PHPUnit test can be launched manually only onto a server with PHP timezone set to TZ+1 Europe/Paris, not a TZ=" . getServerTimeZoneString() . ".\n";
         die;
     }
     $db->begin();
     // This is to have all actions inside a transaction even if test launched without suite.
     print __METHOD__ . "\n";
 }
Example #3
0
/**
 * Return server timezone int.
 *
 * @param	string	$refgmtdate		Reference period for timezone (timezone differs on winter and summer. May be 'now', 'winter' or 'summer')
 * @return 	int						An offset in hour (+1 for Europe/Paris on winter and +2 for Europe/Paris on summer)
 */
function getServerTimeZoneInt($refgmtdate = 'now')
{
    global $conf;
    if (method_exists('DateTimeZone', 'getOffset')) {
        // Method 1 (include daylight)
        $gmtnow = dol_now('gmt');
        $yearref = dol_print_date($gmtnow, '%Y');
        $monthref = dol_print_date($gmtnow, '%m');
        $dayref = dol_print_date($gmtnow, '%d');
        if ($refgmtdate == 'now') {
            $newrefgmtdate = $yearref . '-' . $monthref . '-' . $dayref;
        } elseif ($refgmtdate == 'summer') {
            $newrefgmtdate = $yearref . '-08-01';
        } else {
            $newrefgmtdate = $yearref . '-01-01';
        }
        $localtz = new DateTimeZone(getServerTimeZoneString());
        $localdt = new DateTime($newrefgmtdate, $localtz);
        $tmp = -1 * $localtz->getOffset($localdt);
        //print $refgmtdate.'='.$tmp;
    } else {
        dol_print_error('', 'PHP version must be 5.3+');
        /*
        // Method 2 (does not include daylight, not supported by adodb)
        if ($refgmtdate == 'now')
        {
            if (ini_get("date.timezone")=='UTC') return 0;
            // We don't know server timezone string, so we don't know location, so we can't guess daylight. We assume we use same than client but this may be a bug.
            $gmtnow=dol_now('gmt'); $yearref=dol_print_date($gmtnow,'%Y'); $monthref=dol_print_date($gmtnow,'%m'); $dayref=dol_print_date($gmtnow,'%d');
            if (dol_stringtotime($_SESSION['dol_dst_first']) <= $gmtnow && $gmtnow < dol_stringtotime($_SESSION['dol_dst_second'])) $daylight=1;
            else $daylight=0;
            $tmp=dol_mktime(0,0,0,$monthref,$dayref,$yearref,false,0)-dol_mktime(0,0,0,$monthref,$dayref,$yearref,true,0)-($daylight*3600);
            return 'unknown';    // For true result
        }
        elseif ($refgmtdate == 'summer')
        {
            if (ini_get("date.timezone")=='UTC') return 0;
            // We don't know server timezone string, so we don't know location, so we can't guess daylight. We assume we use same than client but this may be a bug.
            $gmtnow=dol_now('gmt'); $yearref=dol_print_date($gmtnow,'%Y'); $monthref='08'; $dayref='01';
            if (dol_stringtotime($_SESSION['dol_dst_first']) <= dol_stringtotime($yearref.'-'.$monthref.'-'.$dayref) && dol_stringtotime($yearref.'-'.$monthref.'-'.$dayref) < dol_stringtotime($_SESSION['dol_dst_second'])) $daylight=1;
            else $daylight=0;
            $tmp=dol_mktime(0,0,0,$monthref,$dayref,$yearref,false,0)-dol_mktime(0,0,0,$monthref,$dayref,$yearref,true,0)-($daylight*3600);
            return 'unknown';    // For true result
        }
        else $tmp=dol_mktime(0,0,0,1,1,1970);
        */
    }
    $tz = round(($tmp < 0 ? 1 : -1) * abs($tmp / 3600));
    return $tz;
}
$txt = $langs->trans("OSTZ") . ' (variable system TZ): ' . (!empty($_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")) . '' . "<br>\n";
// date.timezone must be in valued defined in http://fr3.php.net/manual/en/timezones.europe.php
$txt .= $langs->trans("Dolibarr constant MAIN_SERVER_TZ") . ': ' . (empty($conf->global->MAIN_SERVER_TZ) ? $langs->trans("NotDefined") : $conf->global->MAIN_SERVER_TZ);
//$txt.=$langs->trans("YouCanEditPHPTZ"); // deprecated
$var = !$var;
print '<tr ' . $bc[$var] . '><td width="300">' . $langs->trans("CurrentTimeZone") . '</td><td>';
// Timezone server PHP
$a = getServerTimeZoneInt('now');
$b = getServerTimeZoneInt('winter');
$c = getServerTimeZoneInt('summer');
$daylight = is_numeric($c) && is_numeric($b) ? round($c - $b) : 'unknown';
//print $a." ".$b." ".$c." ".$daylight;
$val = ($a >= 0 ? '+' : '') . $a;
$val .= ' (' . ($a === 'unknown' ? 'unknown' : ($a >= 0 ? '+' : '') . $a * 3600) . ')';
$val .= ' &nbsp; &nbsp; &nbsp; ' . getServerTimeZoneString();
$val .= ' &nbsp; &nbsp; &nbsp; ' . $langs->trans("DaylingSavingTime") . ': ' . ($daylight === 'unknown' ? 'unknown' : ($a == $c ? yn($daylight) : yn(0) . ($daylight ? '  &nbsp; &nbsp; (' . $langs->trans('YesInSummer') . ')' : '')));
print $form->textwithtooltip($val, $txt, 2, 1, img_info(''));
print '</td></tr>' . "\n";
// value defined in http://fr3.php.net/manual/en/timezones.europe.php
$var = !$var;
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;
print '<tr ' . $bc[$var] . '><td width="300">&nbsp; => dol_print_date(0,"dayhourtext")</td><td>' . dol_print_date(0, "dayhourtext") . '</td>';
$var = !$var;
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;
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>';
// Database timezone
if ($conf->db->type == 'mysql' || $conf->db->type == 'mysqli') {
    $var = !$var;