TestTime.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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/stat_helper.php');
  15. require_once(BASE_ROOT_PATH . '/helper/util_helper.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 testMtrand()
  97. {
  98. for ($i = 0; $i < 100; $i++) {
  99. echo mt_rand(0,6);
  100. echo "\n";
  101. }
  102. $世界 = '⬇';
  103. }
  104. public function testPeriod()
  105. {
  106. $date = date('Y-m-d',time());
  107. $period = ['start' => '08:30'];
  108. $day_start = strtotime("{$date} {$period['start']}");
  109. if(empty($period['end'])) {
  110. $day_end = strtotime("{$date}") + 86400;
  111. }
  112. else {
  113. $day_end = strtotime("{$date} {$period['end']}");
  114. }
  115. }
  116. public function testZero()
  117. {
  118. $x = time();
  119. $date = date('Y-m-d H:i:s',1619020800);
  120. $day_start = strtotime("{$date}");
  121. }
  122. public function testDate()
  123. {
  124. $date = date('Y-m-d',time());
  125. $day_start = strtotime("{$date}");
  126. $begin = $day_start - 6 * 86400;
  127. }
  128. public function testFloat()
  129. {
  130. $t = intval("30.00" + 0.05);
  131. $x = 1.6;
  132. $y = 8;
  133. $t = $x == ($y - 6.4);
  134. $z = $y - 6.4;
  135. $ta = round($x,2) == round($y - 6.4,2);
  136. }
  137. public function testMd5()
  138. {
  139. $x = 'amount=100.00&cardno=1000113200030706234&mchid=10104&order_sn=200000001743&state=CANCEL&trade_no=970664650712097821&key=10086';
  140. $y = md5($x);
  141. }
  142. public function testSuning()
  143. {
  144. $x = date("YmdHis",time());
  145. }
  146. }