RelativeTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of the Carbon package.
  5. *
  6. * (c) Brian Nesbitt <brian@nesbot.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Tests\CarbonImmutable;
  12. use Carbon\CarbonImmutable as Carbon;
  13. use Tests\AbstractTestCase;
  14. class RelativeTest extends AbstractTestCase
  15. {
  16. public function testSecondsSinceMidnight()
  17. {
  18. $d = Carbon::today()->addSeconds(30);
  19. $this->assertSame(30, $d->secondsSinceMidnight());
  20. $d = Carbon::today()->addDays(1);
  21. $this->assertSame(0, $d->secondsSinceMidnight());
  22. $d = Carbon::today()->addDays(1)->addSeconds(120);
  23. $this->assertSame(120, $d->secondsSinceMidnight());
  24. $d = Carbon::today()->addMonths(3)->addSeconds(42);
  25. $this->assertSame(42, $d->secondsSinceMidnight());
  26. }
  27. public function testSecondsUntilEndOfDay()
  28. {
  29. $d = Carbon::today()->endOfDay();
  30. $this->assertSame(0, $d->secondsUntilEndOfDay());
  31. $d = Carbon::today()->endOfDay()->subSeconds(60);
  32. $this->assertSame(60, $d->secondsUntilEndOfDay());
  33. $d = Carbon::create(2014, 10, 24, 12, 34, 56);
  34. $this->assertSame(41103, $d->secondsUntilEndOfDay());
  35. $d = Carbon::create(2014, 10, 24, 0, 0, 0);
  36. $this->assertSame(86399, $d->secondsUntilEndOfDay());
  37. }
  38. }