TestTime.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 testS()
  24. {
  25. $date = date('Y-m-d H:i:S',1517399862);
  26. $x = time();
  27. $date = date('YmdHis',$x);
  28. $date = strtotime($date);
  29. $tm = strtotime('2017-08-01 3:43:00');
  30. $tm1 = strtotime('2017-8-01 3:43:00');
  31. $tm2 = strtotime('2017-08-1 3:43:00');
  32. $tm3 = strtotime('2017-8-1 3:43:00');
  33. $tm3 = strtotime('2017-8-1 03:43:00');
  34. $tm3 = strtotime('2017-8-1 3:43:00');
  35. $tm3 = strtotime('2017-8-1 3:43');
  36. }
  37. public function testDay()
  38. {
  39. $date = date('Y-m-d',time());
  40. $this->mStartm = strtotime(date('Y-m-d',time()));
  41. $this->mEndtm = $this->mStartm + 86400 - 1;
  42. }
  43. public function testWeek()
  44. {
  45. $date = date('Y-m-d',time());
  46. $cur_time = strtotime(date('Y-m-d',time())) + 86400;
  47. $start = $cur_time - 86400 * 7;
  48. $end = $cur_time -1;
  49. $v = ($end - $start + 1) / 86400;
  50. }
  51. public function testMonth()
  52. {
  53. $cur = time();
  54. $cur_date = new DateTime();
  55. $cur_date->setTimestamp($cur);
  56. $inter = new DateInterval('P1M');
  57. $cur_date->sub($inter);
  58. $time = $cur_date->getTimestamp();
  59. }
  60. public function testLastsec()
  61. {
  62. $expried_secs = 10 * 24 * 3600;
  63. $usable_time = time() + $expried_secs;
  64. $cur_date = date('Y-m-d H:i:s',$usable_time);
  65. $cur_time = strtotime(date('Y-m-d',$usable_time)) + 86399;
  66. $curx_date = date('Y-m-d H:i:s',$cur_time);
  67. $cur_time = util::last_day_secs($usable_time);
  68. $cury_date = date('Y-m-d H:i:s',$cur_time);
  69. $delta = $usable_time - $cur_time;
  70. }
  71. public function testRange()
  72. {
  73. $ltm = localtime(strtotime('2020-09-28'),true);
  74. }
  75. private function year_day()
  76. {
  77. $ltm = localtime(strtotime('2020-09-28'),true);
  78. return $ltm['tm_yday'];
  79. }
  80. public function testMtrand()
  81. {
  82. for ($i = 0; $i < 100; $i++) {
  83. echo mt_rand(0,6);
  84. echo "\n";
  85. }
  86. $世界 = '⬇';
  87. }
  88. public function testPeriod()
  89. {
  90. $date = date('Y-m-d',time());
  91. $period = ['start' => '08:30'];
  92. $day_start = strtotime("{$date} {$period['start']}");
  93. if(empty($period['end'])) {
  94. $day_end = strtotime("{$date}") + 86400;
  95. }
  96. else {
  97. $day_end = strtotime("{$date} {$period['end']}");
  98. }
  99. }
  100. public function testDate()
  101. {
  102. $date = date('Y-m-d',time());
  103. $day_start = strtotime("{$date}");
  104. $begin = $day_start - 6 * 86400;
  105. }
  106. public function testFloat()
  107. {
  108. $t = intval("30.00" + 0.05);
  109. $x = 1.6;
  110. $y = 8;
  111. $t = $x == ($y - 6.4);
  112. $z = $y - 6.4;
  113. $ta = round($x,2) == round($y - 6.4,2);
  114. }
  115. public function testMd5()
  116. {
  117. $x = 'amount=100.00&cardno=1000113200030706234&mchid=10104&order_sn=200000001743&state=CANCEL&trade_no=970664650712097821&key=10086';
  118. $y = md5($x);
  119. }
  120. }