StartEndOfTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. * This file is part of the Carbon package.
  4. *
  5. * (c) Brian Nesbitt <brian@nesbot.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. use Carbon\Carbon;
  11. class StartEndOfTest extends TestFixture
  12. {
  13. public function testStartOfDay()
  14. {
  15. $dt = Carbon::now();
  16. $this->assertTrue($dt->startOfDay() instanceof Carbon);
  17. $this->assertCarbon($dt, $dt->year, $dt->month, $dt->day, 0, 0, 0);
  18. }
  19. public function testEndOfDay()
  20. {
  21. $dt = Carbon::now();
  22. $this->assertTrue($dt->endOfDay() instanceof Carbon);
  23. $this->assertCarbon($dt, $dt->year, $dt->month, $dt->day, 23, 59, 59);
  24. }
  25. public function testStartOfMonthIsFluid()
  26. {
  27. $dt = Carbon::now();
  28. $this->assertTrue($dt->startOfMonth() instanceof Carbon);
  29. }
  30. public function testStartOfMonthFromNow()
  31. {
  32. $dt = Carbon::now()->startOfMonth();
  33. $this->assertCarbon($dt, $dt->year, $dt->month, 1, 0, 0, 0);
  34. }
  35. public function testStartOfMonthFromLastDay()
  36. {
  37. $dt = Carbon::create(2000, 1, 31, 2, 3, 4)->startOfMonth();
  38. $this->assertCarbon($dt, 2000, 1, 1, 0, 0, 0);
  39. }
  40. public function testEndOfMonthIsFluid()
  41. {
  42. $dt = Carbon::now();
  43. $this->assertTrue($dt->endOfMonth() instanceof Carbon);
  44. }
  45. public function testEndOfMonth()
  46. {
  47. $dt = Carbon::create(2000, 1, 1, 2, 3, 4)->endOfMonth();
  48. $this->assertCarbon($dt, 2000, 1, 31, 23, 59, 59);
  49. }
  50. public function testEndOfMonthFromLastDay()
  51. {
  52. $dt = Carbon::create(2000, 1, 31, 2, 3, 4)->endOfMonth();
  53. $this->assertCarbon($dt, 2000, 1, 31, 23, 59, 59);
  54. }
  55. }