CreateFromTimestampTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 CreateFromTimestampTest extends TestFixture
  12. {
  13. public function testCreateReturnsDatingInstance()
  14. {
  15. $d = Carbon::createFromTimestamp(Carbon::create(1975, 5, 21, 22, 32, 5)->timestamp);
  16. $this->assertCarbon($d, 1975, 5, 21, 22, 32, 5);
  17. }
  18. public function testCreateFromTimestampUsesDefaultTimezone()
  19. {
  20. $d = Carbon::createFromTimestamp(0);
  21. // We know Toronto is -5 since no DST in Jan
  22. $this->assertSame(1969, $d->year);
  23. $this->assertSame(-5 * 3600, $d->offset);
  24. }
  25. public function testCreateFromTimestampWithDateTimeZone()
  26. {
  27. $d = Carbon::createFromTimestamp(0, new \DateTimeZone('UTC'));
  28. $this->assertSame('UTC', $d->tzName);
  29. $this->assertCarbon($d, 1970, 1, 1, 0, 0, 0);
  30. }
  31. public function testCreateFromTimestampWithString()
  32. {
  33. $d = Carbon::createFromTimestamp(0, 'UTC');
  34. $this->assertCarbon($d, 1970, 1, 1, 0, 0, 0);
  35. $this->assertTrue($d->offset === 0);
  36. $this->assertSame('UTC', $d->tzName);
  37. }
  38. public function testCreateFromTimestampGMTDoesNotUseDefaultTimezone()
  39. {
  40. $d = Carbon::createFromTimestampUTC(0);
  41. $this->assertCarbon($d, 1970, 1, 1, 0, 0, 0);
  42. $this->assertTrue($d->offset === 0);
  43. }
  44. }