CreateFromFormatTest.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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 CreateFromFormatTest extends TestFixture
  12. {
  13. public function testCreateFromFormatReturnsCarbon()
  14. {
  15. $d = Carbon::createFromFormat('Y-m-d H:i:s', '1975-05-21 22:32:11');
  16. $this->assertCarbon($d, 1975, 5, 21, 22, 32, 11);
  17. $this->assertTrue($d instanceof Carbon);
  18. }
  19. public function testCreateFromFormatWithTimezoneString()
  20. {
  21. $d = Carbon::createFromFormat('Y-m-d H:i:s', '1975-05-21 22:32:11', 'Europe/London');
  22. $this->assertCarbon($d, 1975, 5, 21, 22, 32, 11);
  23. $this->assertSame('Europe/London', $d->tzName);
  24. }
  25. public function testCreateFromFormatWithTimezone()
  26. {
  27. $d = Carbon::createFromFormat('Y-m-d H:i:s', '1975-05-21 22:32:11', new \DateTimeZone('Europe/London'));
  28. $this->assertCarbon($d, 1975, 5, 21, 22, 32, 11);
  29. $this->assertSame('Europe/London', $d->tzName);
  30. }
  31. }