[Phpslash-commit] CVS: phpslash-ft/contrib tz_bench.php3,NONE,1.1 tz_test_localtime.php3,NONE,1.1 tz
Brought to you by:
joestewart,
nhruby
From: Joe S. <joe...@us...> - 2002-09-03 15:08:49
|
Update of /cvsroot/phpslash/phpslash-ft/contrib In directory usw-pr-cvs1:/tmp/cvs-serv17261/contrib Added Files: tz_bench.php3 tz_test_localtime.php3 tz_test_mktime.php3 tz_test_strftime.php3 tz_test_strtotime.php3 Log Message: [ 580757 ] Site-wide date formats and TIMEZONES --- NEW FILE: tz_bench.php3 --- <?php require("config.php3"); require("/usr/local/lib/php/Benchmark/Timer.php"); $timer = new Benchmark_Timer; // get code blocks $filename || $filename = 'tz_test_basic.php'; $lines = file($filename); $file = join('',$lines); //echo "file: <pre>", htmlentities($file), "</pre><br>\n"; preg_match_all('/<\?php(.*)\?>/Us',$file,$matches,PREG_SET_ORDER); //echo "matches: <pre>"; //print_r($matches); //echo "</pre>"; // fill in bench array foreach(array(true,false) as $native_flag) { unset($_TZ['obj']); $_TZ['native'] = $native_flag; $native_int = (int) $native_flag; foreach($matches as $i=>$match) { list($string,$code) = $match; if (!$bench[$i]['code']) { ob_start(); highlight_string($string); $bench[$i]['code']=ob_get_contents(); ob_end_clean(); } ob_start(); $marker = $i + 2 * $native_int; $timer->setMarker("Start $marker"); eval($code); $timer->setMarker("End $marker"); $bench[$i][$native_int]['result'] = ob_get_contents(); ob_end_clean(); $bench[$i][$native_int]['time'] = $timer->timeElapsed("Start $marker","End $marker"); } } // output $tpl = new Template($_PSL['templatedir']); // $tpl->debug=true; $tpl->set_file('bench','tz_bench.tpl'); $tpl->set_block('bench','each_code_block','EACH_CODE_BLOCK'); $tpl->set_block('bench','each_link','EACH_LINK'); $tpl->set_var('FILENAME',$filename); $tpl->set_var('PHP_SELF',$PHP_SELF); $float_fmt = "%01.10f"; foreach($bench as $i => $record) { $tpl->set_var(array('CODE'=>$record['code'], 'RESULT_NATIVE'=>$record[1]['result'], 'RESULT_NONNATIVE'=>$record[0]['result'], 'TIME_NATIVE'=>sprintf($float_fmt,$record[1]['time']), 'TIME_NONNATIVE'=>sprintf($float_fmt,$record[0]['time']))); $tpl->parse('EACH_CODE_BLOCK','each_code_block',true); } $_PSL['debug'] = true; $dir = opendir("."); while (false !== ($availablefilename = readdir($dir))) { if (preg_match('/^tz_test_.*\.php/',$availablefilename)) { debug("availablefilename",$availablefilename); $tpl->set_var('AVAILABLE_FILENAME',$availablefilename); $tpl->parse('EACH_LINK','each_link',true); } } $tpl->parse('OUT','bench'); echo $tpl->get('OUT'); ?> --- NEW FILE: tz_test_localtime.php3 --- <?php // set the time zone tz_select('America/Los_Angeles'); echo get_class($_TZ['obj']); ?> <?php // now print_r(tz_localtime(time(),true)); ?> <?php // when do we spring forward? $t = gmmktime(9,59,59,4,7,2002); print_r(tz_localtime($t,true)); print_r(tz_localtime(++$t,true)); ?> <?php // and fall back? $t = gmmktime(8,59,59,10,27,2002); print_r(tz_localtime($t,true)); print_r(tz_localtime(++$t,true)); ?> <?php // set the time zone again, this time with a string tz_select('FST+3FDT,M4.1.0,M10.5.0'); echo get_class($_TZ['obj']); ?> <?php // now print_r(tz_localtime(time())); ?> <?php // when do we spring forward? $t = gmmktime(4,59,59,4,7,2002); print_r(tz_localtime($t,true)); print_r(tz_localtime(++$t,true)); ?> <?php // and fall back? $t = gmmktime(3,59,59,10,27,2002); print_r(tz_localtime($t,true)); print_r(tz_localtime(++$t,true)); ?> --- NEW FILE: tz_test_mktime.php3 --- <?php $fmt = "%A %B %e, %Y, %r %Z\n"; // set the time zone tz_select('America/Los_Angeles'); echo get_class($_TZ['obj']); ?> <?php // Spring Forward in working time zone $t1 = tz_mktime(1,59,59,4,7,2002); echo $t1; ?> <?php // server time: GMT-5 $t2 = mktime(1,59,59,4,7,2002); echo $t2; ?> <?php echo tz_strftime($fmt,$t2); ?> <?php echo strftime($fmt,$t1); ?> --- NEW FILE: tz_test_strftime.php3 --- <?php $fmt = "%A %B %e, %Y, %r %Z\n"; // set the time zone tz_select('America/Los_Angeles'); echo get_class($_TZ['obj']); ?> <?php // now echo tz_strftime($fmt,time()); ?> <?php // when do we spring forward? $t = gmmktime(9,59,59,4,7,2002); echo tz_strftime($fmt,$t); echo tz_strftime($fmt,++$t); ?> <?php // and fall back? $t = gmmktime(8,59,59,10,27,2002); echo tz_strftime($fmt,$t); echo tz_strftime($fmt,++$t); ?> <?php // set the time zone again, this time with a string tz_select('FST+3FDT,M4.1.0,M10.5.0'); echo get_class($_TZ['obj']); ?> <?php // now echo tz_strftime($fmt,time()); ?> <?php // when do we spring forward? $t = gmmktime(4,59,59,4,7,2002); echo tz_strftime($fmt,$t); echo tz_strftime($fmt,++$t); ?> <?php // and fall back? $t = gmmktime(3,59,59,10,27,2002); echo tz_strftime($fmt,$t); echo tz_strftime($fmt,++$t); ?> --- NEW FILE: tz_test_strtotime.php3 --- <?php // set the time zone tz_select('America/Chicago'); echo get_class($_TZ['obj']); $fmt = "%A %B %e, %Y, %r %Z\n"; $date = "7 April 2002 1:59:59am"; ?> <?php $t = tz_strtotime($date); echo $t, "\n"; echo strftime($fmt,$t); ?> <?php echo tz_strftime($fmt, $t); ?> <?php // this should not be adjusted $t2 = tz_strtotime("$date PST"); echo $t2, "\n"; echo tz_strftime($fmt,$t2); ?> <?php echo strftime($fmt,strtotime("12:00pm MDT")); ?> |