예제 #1
0
/**
	 Test Suite
*/
function adodb_date_test()
{
    for ($m = -24; $m <= 24; $m++) {
        echo "{$m} :", adodb_date('d-m-Y', adodb_mktime(0, 0, 0, 1 + $m, 20, 2040)), "<br>";
    }
    error_reporting(E_ALL);
    print "<h4>Testing adodb_date and adodb_mktime. version=" . ADODB_DATE_VERSION . ' PHP=' . PHP_VERSION . "</h4>";
    @set_time_limit(0);
    $fail = false;
    // This flag disables calling of PHP native functions, so we can properly test the code
    if (!defined('ADODB_TEST_DATES')) {
        define('ADODB_TEST_DATES', 1);
    }
    $t = time();
    $fmt = 'Y-m-d H:i:s';
    echo '<pre>';
    echo 'adodb: ', adodb_date($fmt, $t), '<br>';
    echo 'php  : ', date($fmt, $t), '<br>';
    echo '</pre>';
    adodb_date_test_strftime('%Y %m %x %X');
    adodb_date_test_strftime("%A %d %B %Y");
    adodb_date_test_strftime("%H %M S");
    $t = adodb_mktime(0, 0, 0);
    if (!(adodb_date('Y-m-d') == date('Y-m-d'))) {
        print 'Error in ' . adodb_mktime(0, 0, 0) . '<br>';
    }
    $t = adodb_mktime(0, 0, 0, 6, 1, 2102);
    if (!(adodb_date('Y-m-d', $t) == '2102-06-01')) {
        print 'Error in ' . adodb_date('Y-m-d', $t) . '<br>';
    }
    $t = adodb_mktime(0, 0, 0, 2, 1, 2102);
    if (!(adodb_date('Y-m-d', $t) == '2102-02-01')) {
        print 'Error in ' . adodb_date('Y-m-d', $t) . '<br>';
    }
    print "<p>Testing gregorian <=> julian conversion<p>";
    $t = adodb_mktime(0, 0, 0, 10, 11, 1492);
    //http://www.holidayorigins.com/html/columbus_day.html - Friday check
    if (!(adodb_date('D Y-m-d', $t) == 'Fri 1492-10-11')) {
        print 'Error in Columbus landing<br>';
    }
    $t = adodb_mktime(0, 0, 0, 2, 29, 1500);
    if (!(adodb_date('Y-m-d', $t) == '1500-02-29')) {
        print 'Error in julian leap years<br>';
    }
    $t = adodb_mktime(0, 0, 0, 2, 29, 1700);
    if (!(adodb_date('Y-m-d', $t) == '1700-03-01')) {
        print 'Error in gregorian leap years<br>';
    }
    print adodb_mktime(0, 0, 0, 10, 4, 1582) . ' ';
    print adodb_mktime(0, 0, 0, 10, 15, 1582);
    $diff = adodb_mktime(0, 0, 0, 10, 15, 1582) - adodb_mktime(0, 0, 0, 10, 4, 1582);
    if ($diff != 3600 * 24) {
        print " <b>Error in gregorian correction = " . $diff / 3600 / 24 . " days </b><br>";
    }
    print " 15 Oct 1582, Fri=" . (adodb_dow(1582, 10, 15) == 5 ? 'Fri' : '<b>Error</b>') . "<br>";
    print " 4 Oct 1582, Thu=" . (adodb_dow(1582, 10, 4) == 4 ? 'Thu' : '<b>Error</b>') . "<br>";
    print "<p>Testing overflow<p>";
    $t = adodb_mktime(0, 0, 0, 3, 33, 1965);
    if (!(adodb_date('Y-m-d', $t) == '1965-04-02')) {
        print 'Error in day overflow 1 <br>';
    }
    $t = adodb_mktime(0, 0, 0, 4, 33, 1971);
    if (!(adodb_date('Y-m-d', $t) == '1971-05-03')) {
        print 'Error in day overflow 2 <br>';
    }
    $t = adodb_mktime(0, 0, 0, 1, 60, 1965);
    if (!(adodb_date('Y-m-d', $t) == '1965-03-01')) {
        print 'Error in day overflow 3 ' . adodb_date('Y-m-d', $t) . ' <br>';
    }
    $t = adodb_mktime(0, 0, 0, 12, 32, 1965);
    if (!(adodb_date('Y-m-d', $t) == '1966-01-01')) {
        print 'Error in day overflow 4 ' . adodb_date('Y-m-d', $t) . ' <br>';
    }
    $t = adodb_mktime(0, 0, 0, 12, 63, 1965);
    if (!(adodb_date('Y-m-d', $t) == '1966-02-01')) {
        print 'Error in day overflow 5 ' . adodb_date('Y-m-d', $t) . ' <br>';
    }
    $t = adodb_mktime(0, 0, 0, 13, 3, 1965);
    if (!(adodb_date('Y-m-d', $t) == '1966-01-03')) {
        print 'Error in mth overflow 1 <br>';
    }
    print "Testing 2-digit => 4-digit year conversion<p>";
    if (adodb_year_digit_check(00) != 2000) {
        print "Err 2-digit 2000<br>";
    }
    if (adodb_year_digit_check(10) != 2010) {
        print "Err 2-digit 2010<br>";
    }
    if (adodb_year_digit_check(20) != 2020) {
        print "Err 2-digit 2020<br>";
    }
    if (adodb_year_digit_check(30) != 2030) {
        print "Err 2-digit 2030<br>";
    }
    if (adodb_year_digit_check(40) != 1940) {
        print "Err 2-digit 1940<br>";
    }
    if (adodb_year_digit_check(50) != 1950) {
        print "Err 2-digit 1950<br>";
    }
    if (adodb_year_digit_check(90) != 1990) {
        print "Err 2-digit 1990<br>";
    }
    // Test string formating
    print "<p>Testing date formating</p>";
    $fmt = '\\d\\a\\t\\e T Y-m-d H:i:s a A d D F g G h H i j l L m M n O \\R\\F\\C2822 r s t U w y Y z Z 2003';
    $s1 = date($fmt, 0);
    $s2 = adodb_date($fmt, 0);
    if ($s1 != $s2) {
        print " date() 0 failed<br>{$s1}<br>{$s2}<br>";
    }
    flush();
    for ($i = 100; --$i > 0;) {
        $ts = 3600.0 * (rand() % 60000 + rand() % 60000) + rand() % 60000;
        $s1 = date($fmt, $ts);
        $s2 = adodb_date($fmt, $ts);
        //print "$s1 <br>$s2 <p>";
        $pos = strcmp($s1, $s2);
        if ($s1 != $s2) {
            for ($j = 0, $k = strlen($s1); $j < $k; $j++) {
                if ($s1[$j] != $s2[$j]) {
                    print substr($s1, $j) . ' ';
                    break;
                }
            }
            print "<b>Error date(): {$ts}<br><pre> \n&nbsp; \"{$s1}\" (date len=" . strlen($s1) . ")\n&nbsp; \"{$s2}\" (adodb_date len=" . strlen($s2) . ")</b></pre><br>";
            $fail = true;
        }
        $a1 = getdate($ts);
        $a2 = adodb_getdate($ts);
        $rez = array_diff($a1, $a2);
        if (sizeof($rez) > 0) {
            print "<b>Error getdate() {$ts}</b><br>";
            print_r($a1);
            print "<br>";
            print_r($a2);
            print "<p>";
            $fail = true;
        }
    }
    // Test generation of dates outside 1901-2038
    print "<p>Testing random dates between 100 and 4000</p>";
    adodb_date_test_date(100, 1);
    for ($i = 100; --$i >= 0;) {
        $y1 = 100 + rand(0, 1970 - 100);
        $m = rand(1, 12);
        adodb_date_test_date($y1, $m);
        $y1 = 3000 - rand(0, 3000 - 1970);
        adodb_date_test_date($y1, $m);
    }
    print '<p>';
    $start = 1960 + rand(0, 10);
    $yrs = 12;
    $i = 365.25 * 86400 * ($start - 1970);
    $offset = 36000 + rand(10000, 60000);
    $max = 365 * $yrs * 86400;
    $lastyear = 0;
    // we generate a timestamp, convert it to a date, and convert it back to a timestamp
    // and check if the roundtrip broke the original timestamp value.
    print "Testing {$start} to " . ($start + $yrs) . ", or {$max} seconds, offset={$offset}: ";
    $cnt = 0;
    for ($max += $i; $i < $max; $i += $offset) {
        $ret = adodb_date('m,d,Y,H,i,s', $i);
        $arr = explode(',', $ret);
        if ($lastyear != $arr[2]) {
            $lastyear = $arr[2];
            print " {$lastyear} ";
            flush();
        }
        $newi = adodb_mktime($arr[3], $arr[4], $arr[5], $arr[0], $arr[1], $arr[2]);
        if ($i != $newi) {
            print "Error at {$i}, adodb_mktime returned {$newi} ({$ret})";
            $fail = true;
            break;
        }
        $cnt += 1;
    }
    echo "Tested {$cnt} dates<br>";
    if (!$fail) {
        print "<p>Passed !</p>";
    } else {
        print "<p><b>Failed</b> :-(</p>";
    }
}
예제 #2
0
 /**
  * Render Meta Box content.
  *
  * @param WP_Post $post The post object.
  * */
 public function cred_pe_render_meta_box_content($post)
 {
     $post_expiration_time = get_post_meta($post->ID, $this->_post_expiration_time_field, true);
     if (empty($post_expiration_time)) {
         $values = array('date' => '', 'hours' => 0, 'minutes' => 0);
     } else {
         $values = adodb_getdate($post_expiration_time);
         $values['minutes'] = floor($values['minutes'] / 15) * 15;
         $date_format = preg_replace('/(\\s)*[:@aAghGHisTcr]+(\\s)*/', '', get_option('date_format'));
         $date_format = preg_replace('/[,-\\/\\s]+$/', '', $date_format);
         $values['date'] = adodb_date($date_format, $post_expiration_time);
     }
     $post_expiration_action = get_post_meta($post->ID, $this->_post_expiration_action_field, true);
     if (!isset($post_expiration_action['post_status'])) {
         $post_expiration_action['post_status'] = '';
     }
     echo CRED_Loader::tpl('pe_post_meta_box', array('cred_post_expiration' => $this, 'post_expiration_time' => $post_expiration_time, 'post_expiration_action' => $post_expiration_action, 'values' => $values, 'post_expiration_slug' => $this->_post_expiration_slug, 'time_field_name' => $this->_post_expiration_time_field, 'action_field_name' => $this->_post_expiration_action_field));
 }
예제 #3
0
{
    $newparam=$param;   // newparam is for birthday links
    $newparam=preg_replace('/action=show_month&?/i','',$newparam);
    $newparam=preg_replace('/action=show_week&?/i','',$newparam);
    $newparam=preg_replace('/day=[0-9][0-9]&?/i','',$newparam);
    $newparam=preg_replace('/month=[0-9][0-9]&?/i','',$newparam);
    $newparam=preg_replace('/year=[0-9]+&?/i','',$newparam);
    // Code to show just one day
    $style='cal_current_month';
    $today=0;
    $todayarray=dol_getdate($now,'fast');
    if ($todayarray['mday']==$day && $todayarray['mon']==$month && $todayarray['year']==$year) $today=1;
    if ($today) $style='cal_today';

    $timestamp=dol_mktime(12,0,0,$month,$day,$year);
    $arraytimestamp=adodb_getdate(dol_mktime(12,0,0,$month,$day,$year));
    echo '<table width="100%" class="nocellnopadd">';
    echo ' <tr class="liste_titre">';
    echo '  <td align="center">'.$langs->trans("Day".$arraytimestamp['wday'])."</td>\n";
    echo " </tr>\n";
    echo " <tr>\n";
    echo '  <td class="'.$style.'" width="14%" valign="top"  nowrap="nowrap">';
    $maxnbofchar=80;
    show_day_events ($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300);
    echo "</td>\n";
    echo " </tr>\n";
    echo '</table>';
}


$db->close();
예제 #4
0
 function GetDateTime($ts)
 {
     if ($this->UseAdodbTime) {
         return adodb_getdate($ts);
     } else {
         return getdate($ts);
     }
 }
예제 #5
0
 function formatDate($value)
 {
     if (!is_numeric($value)) {
         $v = str2date($value);
         if (!is_null($v)) {
             $value = $v;
         } else {
             return $this->stdFormat($value);
         }
     }
     if (is_numeric($value)) {
         $dateParts = adodb_getdate($value);
         //speed: adodb_getdate is slow!!!
         $year = $dateParts['year'];
         $month = $dateParts['mon'];
         $day = $dateParts['mday'];
         $hour = $dateParts['hours'];
         $min = $dateParts['minutes'];
         $secs = $dateParts['seconds'];
         $dow = $dateParts['wday'];
     }
     $_day_power = 86400;
     $_hour_power = 3600;
     $_min_power = 60;
     //cannot replace Epoch by constant, because value of adodb_mktime depends on time zone
     //but we compute it only once ....
     static $_MicrosoftEpoch;
     //speed: cache $epoch (1.5sec)
     if (!$_MicrosoftEpoch) {
         $_MicrosoftEpoch = adodb_mktime(0, 0, 0, 12, 30, 1899);
     }
     if (sizeof($this->formatParts) == 1) {
         $fmt = $this->formatParts[0];
     } elseif ($value == $_MicrosoftEpoch) {
         if ($this->formatParts[2]) {
             $fmt = $this->formatParts[2];
         } else {
             $fmt = $this->formatParts[0];
         }
     } elseif (is_null($value)) {
         $fmt = $this->formatParts[3];
     } else {
         $fmt = $this->formatParts[0];
     }
     $res = '';
     if (!isset($fmt)) {
         if (is_null($value)) {
             return '';
         } else {
             if ($year == 1899 && $month == 12 && ($day = 30)) {
                 if ($hour == 0 && $min == 0 && $sec == 0) {
                     return null;
                 } else {
                     return format($value, 'long time');
                 }
             } else {
                 if ($hour == 0 && $min == 0 && $sec == 0) {
                     return format($value, 'short date');
                 } else {
                     return format($value, 'general date');
                 }
             }
         }
     }
     foreach ($fmt as $fmtItem) {
         switch ($fmtItem['token']) {
             case $this->STRING:
                 $res .= $fmtItem['value'];
                 break;
             case 'd':
                 $res .= $day;
                 $this->OnDayFormat();
                 break;
             case 'dd':
                 $res .= $this->twoDigits($day);
                 $this->OnDayFormat();
                 break;
             case 'ddd':
                 $res .= strftime('%a', $_day_power * (3 + $dow));
                 break;
             case 'dddd':
                 $res .= strftime('%A', $_day_power * (3 + $dow));
                 break;
             case 'ddddd':
                 $res .= format($value, 'short date');
                 break;
             case 'dddddd':
                 $res .= format($value, 'long date');
                 break;
             case 'm':
                 $res .= $month;
                 $this->OnMonthFormat();
                 break;
             case 'mm':
                 $res .= $this->twoDigits($month);
                 $this->OnMonthFormat();
                 break;
             case 'mmm':
                 $res .= strftime('%b', mktime(0, 0, 0, $month, 2, 1971));
                 $this->OnMonthFormat();
                 break;
             case 'mmmm':
                 $res .= strftime('%B', mktime(0, 0, 0, $month, 2, 1971));
                 $this->OnMonthFormat();
                 break;
             case 'y':
                 $res .= $dateParts['yday'] + 1;
                 break;
             case 'yy':
                 $y = $year % 100;
                 $res .= $this->twoDigits($y);
                 break;
             case 'yyyy':
                 $res .= $year;
                 break;
             case 'h':
                 $res .= $hour;
                 break;
             case 'hh':
                 $res .= $this->twoDigits($hour);
                 break;
             case 'n':
                 $res .= $min;
                 break;
             case 'nn':
                 $res .= $this->twoDigits($min);
                 break;
             case 's':
                 $res .= $secs;
                 break;
             case 'ss':
                 $res .= $this->twoDigits($secs);
                 break;
             case 'ttttt':
                 $res .= format($value, 'long time');
                 break;
             case '/':
                 $res .= $this->getDateSep();
                 break;
             default:
                 $res .= $fmtItem['value'];
         }
     }
     return $res;
 }
예제 #6
0
/**
 *	Return an array with date info
 *  PHP getdate is restricted to the years 1901-2038 on Unix and 1970-2038 on Windows.
 *	@param		timestamp		Timestamp
 *	@param		fast			Fast mode
 *	@return		array			Array of informations
 *				If no fast mode:
 *				'seconds' => $secs,
 *				'minutes' => $min,
 *				'hours' => $hour,
 *				'mday' => $day,
 *				'wday' => $dow,
 *				'mon' => $month,
 *				'year' => $year,
 *				'yday' => floor($secsInYear/$_day_power),
 *				'weekday' => gmdate('l',$_day_power*(3+$dow)),
 *				'month' => gmdate('F',mktime(0,0,0,$month,2,1971)),
 *				If fast mode:
 *				'seconds' => $secs,
 *				'minutes' => $min,
 *				'hours' => $hour,
 *				'mday' => $day,
 *				'mon' => $month,
 *				'year' => $year,
 *				'yday' => floor($secsInYear/$_day_power),
 *				'leap' => $leaf,
 *				'ndays' => $ndays
 */
function dol_getdate($timestamp, $fast = false)
{
    $usealternatemethod = false;
    if ($timestamp <= 0) {
        $usealternatemethod = true;
    }
    // <= 1970
    if ($timestamp >= 2145913200) {
        $usealternatemethod = true;
    }
    // >= 2038
    if ($usealternatemethod) {
        $arrayinfo = adodb_getdate($timestamp, $fast);
    } else {
        $arrayinfo = getdate($timestamp);
    }
    return $arrayinfo;
}
예제 #7
0
파일: clDate.php 프로젝트: jeromecc/tuv2
 function getYear()
 {
     $array = adodb_getdate($this->timestamp);
     return $array['year'];
 }
예제 #8
0
/**
 *	Return an array with locale date info.
 *  PHP getdate is restricted to the years 1901-2038 on Unix and 1970-2038 on Windows
 *  WARNING: This function always use PHP server timezone to return locale informations !!!
 *  Usage must be avoid.
 *  FIXME: Replace this with PHP date function and a parameter $gm
 *
 *	@param	int			$timestamp      Timestamp
 *	@param	boolean		$fast           Fast mode
 *	@return	array						Array of informations
 *										If no fast mode:
 *										'seconds' => $secs,
 *										'minutes' => $min,
 *										'hours' => $hour,
 *										'mday' => $day,
 *										'wday' => $dow,		0=sunday, 6=saturday
 *										'mon' => $month,
 *										'year' => $year,
 *										'yday' => floor($secsInYear/$_day_power),
 *										'weekday' => gmdate('l',$_day_power*(3+$dow)),
 *										'month' => gmdate('F',mktime(0,0,0,$month,2,1971)),
 *										If fast mode:
 *										'seconds' => $secs,
 *										'minutes' => $min,
 *										'hours' => $hour,
 *										'mday' => $day,
 *										'mon' => $month,
 *										'year' => $year,
 *										'yday' => floor($secsInYear/$_day_power),
 *										'leap' => $leaf,
 *										'ndays' => $ndays
 * 	@see 								dol_print_date, dol_stringtotime, dol_mktime
 */
function dol_getdate($timestamp, $fast = false)
{
    global $conf;
    $usealternatemethod = false;
    if ($timestamp <= 0) {
        $usealternatemethod = true;
    }
    // <= 1970
    if ($timestamp >= 2145913200) {
        $usealternatemethod = true;
    }
    // >= 2038
    if ($usealternatemethod) {
        $arrayinfo = adodb_getdate($timestamp, $fast);
    } else {
        $arrayinfo = getdate($timestamp);
        /*$startday=isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:1;
        		if($startday==1)
        		{
        			if ($arrayinfo["wday"]==0)
        			{
        				$arrayinfo["wday"]=6;
        			}
        			else
        			{
        				$arrayinfo["wday"]=$arrayinfo["wday"]-1;
        			}
        		}*/
    }
    return $arrayinfo;
}
예제 #9
0
/**
 * Alias for adodb_getdate()
 */
function carl_getdate($timestamp = false, $fast = false)
{
    return adodb_getdate($timestamp, $fast);
}
예제 #10
0
 /**
  * Function display's the date.
  *
  * @param array $record array with date
  * @param string $mode
  *
  * @return string formatted date string
  */
 public function display($record, $mode)
 {
     $value = isset($record[$this->fieldName()]) ? $record[$this->fieldName()] : null;
     if (!is_array($value) || empty($value['month']) || empty($value['day']) || empty($value['year'])) {
         return '';
     }
     $tmp_date = adodb_getdate(adodb_mktime(0, 0, 0, $value['month'], $value['day'], $value['year']));
     if (!empty($tmp_date)) {
         $d = $this->formatDate($tmp_date, $this->m_date_format_view, $this->hasFlag(self::AF_DATE_DISPLAY_DAY));
         if ($mode == 'list') {
             $d = str_replace(' ', '&nbsp;', $d);
         }
         return $d;
     } else {
         return '&nbsp;';
     }
 }