NowAndOtherStaticHelpersTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 NowAndOtherStaticHelpersTest extends TestFixture
  12. {
  13. public function testNow()
  14. {
  15. $dt = Carbon::now();
  16. $this->assertSame(time(), $dt->timestamp);
  17. }
  18. public function testNowWithTimezone()
  19. {
  20. $dt = Carbon::now('Europe/London');
  21. $this->assertSame(time(), $dt->timestamp);
  22. $this->assertSame('Europe/London', $dt->tzName);
  23. }
  24. public function testToday()
  25. {
  26. $dt = Carbon::today();
  27. $this->assertSame(date('Y-m-d 00:00:00'), $dt->toDateTimeString());
  28. }
  29. public function testTodayWithTimezone()
  30. {
  31. $dt = Carbon::today('Europe/London');
  32. $dt2 = new \DateTime('now', new \DateTimeZone('Europe/London'));
  33. $this->assertSame($dt2->format('Y-m-d 00:00:00'), $dt->toDateTimeString());
  34. }
  35. public function testTomorrow()
  36. {
  37. $dt = Carbon::tomorrow();
  38. $dt2 = new \DateTime('tomorrow');
  39. $this->assertSame($dt2->format('Y-m-d 00:00:00'), $dt->toDateTimeString());
  40. }
  41. public function testTomorrowWithTimezone()
  42. {
  43. $dt = Carbon::tomorrow('Europe/London');
  44. $dt2 = new \DateTime('tomorrow', new \DateTimeZone('Europe/London'));
  45. $this->assertSame($dt2->format('Y-m-d 00:00:00'), $dt->toDateTimeString());
  46. }
  47. public function testYesterday()
  48. {
  49. $dt = Carbon::yesterday();
  50. $dt2 = new \DateTime('yesterday');
  51. $this->assertSame($dt2->format('Y-m-d 00:00:00'), $dt->toDateTimeString());
  52. }
  53. public function testYesterdayWithTimezone()
  54. {
  55. $dt = Carbon::yesterday('Europe/London');
  56. $dt2 = new \DateTime('yesterday', new \DateTimeZone('Europe/London'));
  57. $this->assertSame($dt2->format('Y-m-d 00:00:00'), $dt->toDateTimeString());
  58. }
  59. }