TestTime.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/5/25
  6. * Time: 上午10:21
  7. */
  8. define('APP_ID', 'test');
  9. define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
  10. require_once(BASE_ROOT_PATH . '/global.php');
  11. require_once(BASE_CORE_PATH . '/lrlz.php');
  12. require_once(BASE_ROOT_PATH . '/fooder.php');
  13. require_once(BASE_ROOT_PATH . '/helper/stat_helper.php');
  14. require_once(BASE_ROOT_PATH . '/helper/util_helper.php');
  15. require_once(BASE_ROOT_PATH . '/helper/refill/functional.php');
  16. use PHPUnit\Framework\TestCase;
  17. class TestTime extends TestCase
  18. {
  19. public static function setUpBeforeClass() : void
  20. {
  21. Base::run_util();
  22. }
  23. public function testMicro()
  24. {
  25. $start = microtime(true);
  26. $end = microtime(true);
  27. Log::record("request time=" . ($end - $start),Log::DEBUG);
  28. for ($i = 0; $i < 10000; $i++)
  29. {
  30. $x = microtime();
  31. $y = (float)$x;
  32. Log::record("{$y}",Log::DEBUG);
  33. }
  34. $x = microtime();
  35. $y = (float)$x;
  36. $z = (int)$x;
  37. $x = sprintf('%03d', $y * 1000000);
  38. }
  39. public function testS()
  40. {
  41. $date = date('Y-m-d H:i:S', 1517399862);
  42. $x = time();
  43. $date = date('YmdHis', $x);
  44. $date = strtotime($date);
  45. $tm = strtotime('2017-08-01 3:43:00');
  46. $tm1 = strtotime('2017-8-01 3:43:00');
  47. $tm2 = strtotime('2017-08-1 3:43:00');
  48. $tm3 = strtotime('2017-8-1 3:43:00');
  49. $tm3 = strtotime('2017-8-1 03:43:00');
  50. $tm3 = strtotime('2017-8-1 3:43:00');
  51. $tm3 = strtotime('2017-8-1 3:43');
  52. }
  53. public function testDay()
  54. {
  55. $date = date('Y-m-d',time());
  56. $this->mStartm = strtotime(date('Y-m-d',time()));
  57. $this->mEndtm = $this->mStartm + 86400 - 1;
  58. }
  59. public function testWeek()
  60. {
  61. $date = date('Y-m-d',time());
  62. $cur_time = strtotime(date('Y-m-d',time())) + 86400;
  63. $start = $cur_time - 86400 * 7;
  64. $end = $cur_time -1;
  65. $v = ($end - $start + 1) / 86400;
  66. }
  67. public function testMonth()
  68. {
  69. $cur = time();
  70. $cur_date = new DateTime();
  71. $cur_date->setTimestamp($cur);
  72. $inter = new DateInterval('P1M');
  73. $cur_date->sub($inter);
  74. $time = $cur_date->getTimestamp();
  75. }
  76. public function testLastsec()
  77. {
  78. $expried_secs = 10 * 24 * 3600;
  79. $usable_time = time() + $expried_secs;
  80. $cur_date = date('Y-m-d H:i:s',$usable_time);
  81. $cur_time = strtotime(date('Y-m-d',$usable_time)) + 86399;
  82. $curx_date = date('Y-m-d H:i:s',$cur_time);
  83. $cur_time = util::last_day_secs($usable_time);
  84. $cury_date = date('Y-m-d H:i:s',$cur_time);
  85. $delta = $usable_time - $cur_time;
  86. }
  87. public function testRange()
  88. {
  89. $ltm = localtime(strtotime('2020-09-28'),true);
  90. }
  91. private function year_day()
  92. {
  93. $ltm = localtime(strtotime('2020-09-28'),true);
  94. return $ltm['tm_yday'];
  95. }
  96. public function testPeriod()
  97. {
  98. $date = date('Y-m-d',time());
  99. $period = ['start' => '08:30'];
  100. $day_start = strtotime("{$date} {$period['start']}");
  101. if(empty($period['end'])) {
  102. $day_end = strtotime("{$date}") + 86400;
  103. }
  104. else {
  105. $day_end = strtotime("{$date} {$period['end']}");
  106. }
  107. }
  108. public function testZero()
  109. {
  110. $x = time();
  111. $date = date('Y-m-d H:i:s',1619020800);
  112. $day_start = strtotime("{$date}");
  113. }
  114. public function testDate()
  115. {
  116. $date = date('Y-m-d',time());
  117. $day_start = strtotime("{$date}");
  118. $begin = $day_start - 6 * 86400;
  119. }
  120. public function testFloat()
  121. {
  122. $t = intval("30.00" + 0.05);
  123. $x = 1.6;
  124. $y = 8;
  125. $t = $x == ($y - 6.4);
  126. $z = $y - 6.4;
  127. $ta = round($x,2) == round($y - 6.4,2);
  128. }
  129. public function testMd5()
  130. {
  131. $x = 'amount=100.00&cardno=1000113200030706234&mchid=10104&order_sn=200000001743&state=CANCEL&trade_no=970664650712097821&key=10086';
  132. $y = md5($x);
  133. }
  134. public function testSuning()
  135. {
  136. $x = date("YmdHis",time());
  137. }
  138. public function testSort()
  139. {
  140. //不过载的排在前面
  141. $ascending = function ($l, $r) {
  142. return $l < $r ? -1 : 1;
  143. };
  144. $usable_items = [];
  145. usort($usable_items, $ascending);
  146. }
  147. public function testChSort()
  148. {
  149. $data = ['黄刚','首浩话费','领袖科技','闪光点','金蝠国际','金灏便民','远行云商','迅银-加油','车猪猪','车卫士-话费3分钟','车卫士-话费10分钟','车卫士-24h慢充','车卫士','赤豹-6H慢充','裕寅旺-话费','裕寅旺-加油','葳崚科技','胡寿平','翼连','童维森-话费','秋成','甄祺-普充','甄祺-快充','琳珠-快充','琳珠','海南劲峰','海南公象','测试账户','泽恒加油','泽恒','河马代缴','沃斯达','比特烽-话费','武汉创悦慢充','武汉中瑞','武安创悦','橘米科技','橘米','椰子测试','椰子','森克','果子pay','木涛','有甯高价10分钟','有甯三网快充','有甯-24h慢充','有寗-加油','有寗-3分钟','有寗-10分钟','星凯信息2','星凯信息','星之予-话费','星之予','易派','易商惠众','易加互动','昊泽通信','昊泽慢充','旭友-普充','旭友-快充','方诺-慢充','抱阳','恒易迅-话费','恒易迅-慢充24h','恒易迅','小口袋-2h','小口袋','妃霓墨蜀','奇小宝','天采科技优质普充','天采科技','天采快充','国瑞-加油','和辉-普充','和辉-慢充','和辉-加油','吉瑞话费','华彬-话费','劲峰钱包-24h','劲峰钱包','劲峰混充','劲峰加油','劲峰三网快充','创悦慢充','创哈-加油','元培-24h慢充','停划算','亿畅通','享省科技','云洋','乐优-话费','中房','中乐-话费3分钟','中乐-话费24h','中乐-话费10分钟','中乐-快充','中乐','东典-话费','东东网-慢充24h','东东网','万图拍','一号话费','yezi01'];
  150. $x = [];
  151. foreach ($data as $item) {
  152. $x[] = ['p' => Pinyin::getPinyin($item), 'o' => $item];
  153. }
  154. $asc = function ($l,$r)
  155. {
  156. $lp = $l['p'];
  157. $rp = $r['p'];
  158. $lo = $l['o'];
  159. $ro = $r['o'];
  160. if($lp == $rp) {
  161. return 0;
  162. }
  163. else {
  164. return strcmp($lp,$rp);
  165. }
  166. };
  167. usort($x,$asc);
  168. $y = $data;
  169. }
  170. public function testMtrand()
  171. {
  172. for ($i = 0; $i < 10000; $i++) {
  173. $val = mt_rand(1,200);
  174. Log::record("{$val}",Log::DEBUG);
  175. }
  176. }
  177. public function testIsDay()
  178. {
  179. $ret = refill\functional::isDay();
  180. }
  181. public function testFormat()
  182. {
  183. $x = date("Y-m-d H:i:s");
  184. }
  185. }