123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 2017/5/25
- * Time: 上午10:21
- */
- define('APP_ID', 'test');
- define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
- require_once(BASE_ROOT_PATH . '/global.php');
- require_once(BASE_CORE_PATH . '/lrlz.php');
- require_once(BASE_ROOT_PATH . '/fooder.php');
- require_once(BASE_ROOT_PATH . '/helper/stat_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/stat_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/util_helper.php');
- use PHPUnit\Framework\TestCase;
- class TestTime extends TestCase
- {
- public static function setUpBeforeClass() : void
- {
- Base::run_util();
- }
- public function testMicro()
- {
- $start = microtime(true);
- $end = microtime(true);
- Log::record("request time=" . ($end - $start),Log::DEBUG);
- for ($i = 0; $i < 10000; $i++)
- {
- $x = microtime();
- $y = (float)$x;
- Log::record("{$y}",Log::DEBUG);
- }
- $x = microtime();
- $y = (float)$x;
- $z = (int)$x;
- $x = sprintf('%03d', $y * 1000000);
- }
- public function testS()
- {
- $date = date('Y-m-d H:i:S',1517399862);
- $x = time();
- $date = date('YmdHis',$x);
- $date = strtotime($date);
- $tm = strtotime('2017-08-01 3:43:00');
- $tm1 = strtotime('2017-8-01 3:43:00');
- $tm2 = strtotime('2017-08-1 3:43:00');
- $tm3 = strtotime('2017-8-1 3:43:00');
- $tm3 = strtotime('2017-8-1 03:43:00');
- $tm3 = strtotime('2017-8-1 3:43:00');
- $tm3 = strtotime('2017-8-1 3:43');
- }
- public function testDay()
- {
- $date = date('Y-m-d',time());
- $this->mStartm = strtotime(date('Y-m-d',time()));
- $this->mEndtm = $this->mStartm + 86400 - 1;
- }
- public function testWeek()
- {
- $date = date('Y-m-d',time());
- $cur_time = strtotime(date('Y-m-d',time())) + 86400;
- $start = $cur_time - 86400 * 7;
- $end = $cur_time -1;
- $v = ($end - $start + 1) / 86400;
- }
- public function testMonth()
- {
- $cur = time();
- $cur_date = new DateTime();
- $cur_date->setTimestamp($cur);
- $inter = new DateInterval('P1M');
- $cur_date->sub($inter);
- $time = $cur_date->getTimestamp();
- }
- public function testLastsec()
- {
- $expried_secs = 10 * 24 * 3600;
- $usable_time = time() + $expried_secs;
- $cur_date = date('Y-m-d H:i:s',$usable_time);
- $cur_time = strtotime(date('Y-m-d',$usable_time)) + 86399;
- $curx_date = date('Y-m-d H:i:s',$cur_time);
- $cur_time = util::last_day_secs($usable_time);
- $cury_date = date('Y-m-d H:i:s',$cur_time);
- $delta = $usable_time - $cur_time;
- }
- public function testRange()
- {
- $ltm = localtime(strtotime('2020-09-28'),true);
- }
- private function year_day()
- {
- $ltm = localtime(strtotime('2020-09-28'),true);
- return $ltm['tm_yday'];
- }
- public function testMtrand()
- {
- for ($i = 0; $i < 100; $i++) {
- echo mt_rand(0,6);
- echo "\n";
- }
- $世界 = '⬇';
- }
- public function testPeriod()
- {
- $date = date('Y-m-d',time());
- $period = ['start' => '08:30'];
- $day_start = strtotime("{$date} {$period['start']}");
- if(empty($period['end'])) {
- $day_end = strtotime("{$date}") + 86400;
- }
- else {
- $day_end = strtotime("{$date} {$period['end']}");
- }
- }
- public function testZero()
- {
- $x = time();
- $date = date('Y-m-d H:i:s',1619020800);
- $day_start = strtotime("{$date}");
- }
- public function testDate()
- {
- $date = date('Y-m-d',time());
- $day_start = strtotime("{$date}");
- $begin = $day_start - 6 * 86400;
- }
- public function testFloat()
- {
- $t = intval("30.00" + 0.05);
- $x = 1.6;
- $y = 8;
- $t = $x == ($y - 6.4);
- $z = $y - 6.4;
- $ta = round($x,2) == round($y - 6.4,2);
- }
- public function testMd5()
- {
- $x = 'amount=100.00&cardno=1000113200030706234&mchid=10104&order_sn=200000001743&state=CANCEL&trade_no=970664650712097821&key=10086';
- $y = md5($x);
- }
- public function testSuning()
- {
- $x = date("YmdHis",time());
- }
- }
|