Keine Beschreibung

CreateFromTimestampTest.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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->assertSame(0, $d->offset);
  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->assertSame(0, $d->offset);
  43. }
  44. }