DateTestTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace OrderCountingRecordService;
  3. use App\Services\CacheService;
  4. use App\Services\OrderCountingRecordService;
  5. use Carbon\Carbon;
  6. use DateInterval;
  7. use DatePeriod;
  8. use DateTime;
  9. use Tests\TestCase;
  10. class DateTestTest extends TestCase
  11. {
  12. /** @var OrderCountingRecordService $orderCountingRecordService */
  13. public $orderCountingRecordService;
  14. public function setUp(): void
  15. {
  16. parent::setUp();
  17. $this->orderCountingRecordService = app(OrderCountingRecordService::class);
  18. }
  19. /**
  20. * @test
  21. */
  22. public function carbon_date_equals()
  23. {
  24. $this->assertTrue('2020-11-25' == Carbon::now()->format('Y-m-d'));
  25. $this->assertTrue('2020-48' == Carbon::now()->year . '-' . Carbon::now()->week);
  26. $this->assertTrue('2020-11' == Carbon::now()->year . '-' . Carbon::now()->month);
  27. }
  28. /**
  29. * @test
  30. */
  31. public function compare_date()
  32. {
  33. $dateStr = '2020-12-30';
  34. $end = Carbon::parse($dateStr)->gt(Carbon::now()) ? Carbon::now()->toDateString() : $dateStr;
  35. dd($end);
  36. }
  37. /**
  38. * @test
  39. */
  40. public function for_date()
  41. {
  42. $start = Carbon::now()->subMonth()->toDateString();
  43. $end = Carbon::now()->toDateString();
  44. $unit = '月';
  45. dump($start, $end, $unit);
  46. $dateArray =$this->orderCountingRecordService->periodDateToArray($start, $end, $unit);
  47. dd($dateArray);
  48. }
  49. }