123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- <?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/util_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/refill/functional.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 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());
- }
- public function testSort()
- {
- //不过载的排在前面
- $ascending = function ($l, $r) {
- return $l < $r ? -1 : 1;
- };
- $usable_items = [];
- usort($usable_items, $ascending);
- }
- public function testChSort()
- {
- $data = ['黄刚','首浩话费','领袖科技','闪光点','金蝠国际','金灏便民','远行云商','迅银-加油','车猪猪','车卫士-话费3分钟','车卫士-话费10分钟','车卫士-24h慢充','车卫士','赤豹-6H慢充','裕寅旺-话费','裕寅旺-加油','葳崚科技','胡寿平','翼连','童维森-话费','秋成','甄祺-普充','甄祺-快充','琳珠-快充','琳珠','海南劲峰','海南公象','测试账户','泽恒加油','泽恒','河马代缴','沃斯达','比特烽-话费','武汉创悦慢充','武汉中瑞','武安创悦','橘米科技','橘米','椰子测试','椰子','森克','果子pay','木涛','有甯高价10分钟','有甯三网快充','有甯-24h慢充','有寗-加油','有寗-3分钟','有寗-10分钟','星凯信息2','星凯信息','星之予-话费','星之予','易派','易商惠众','易加互动','昊泽通信','昊泽慢充','旭友-普充','旭友-快充','方诺-慢充','抱阳','恒易迅-话费','恒易迅-慢充24h','恒易迅','小口袋-2h','小口袋','妃霓墨蜀','奇小宝','天采科技优质普充','天采科技','天采快充','国瑞-加油','和辉-普充','和辉-慢充','和辉-加油','吉瑞话费','华彬-话费','劲峰钱包-24h','劲峰钱包','劲峰混充','劲峰加油','劲峰三网快充','创悦慢充','创哈-加油','元培-24h慢充','停划算','亿畅通','享省科技','云洋','乐优-话费','中房','中乐-话费3分钟','中乐-话费24h','中乐-话费10分钟','中乐-快充','中乐','东典-话费','东东网-慢充24h','东东网','万图拍','一号话费','yezi01'];
- $x = [];
- foreach ($data as $item) {
- $x[] = ['p' => Pinyin::getPinyin($item), 'o' => $item];
- }
- $asc = function ($l,$r)
- {
- $lp = $l['p'];
- $rp = $r['p'];
- $lo = $l['o'];
- $ro = $r['o'];
- if($lp == $rp) {
- return 0;
- }
- else {
- return strcmp($lp,$rp);
- }
- };
- usort($x,$asc);
- $y = $data;
- }
- public function testMtrand()
- {
- for ($i = 0; $i < 10000; $i++) {
- $val = mt_rand(1,200);
- Log::record("{$val}",Log::DEBUG);
- }
- }
- public function testIsDay()
- {
- $ret = refill\functional::isDay();
- }
- public function testFormat()
- {
- $x = date("Y-m-d H:i:s");
- }
- }
|