TestTime.php 3.5 KB

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