No Description

InstanceTest.php 1.1KB

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 InstanceTest extends TestFixture
  12. {
  13. public function testInstanceFromDateTime()
  14. {
  15. $dating = Carbon::instance(\DateTime::createFromFormat('Y-m-d H:i:s', '1975-05-21 22:32:11'));
  16. $this->assertCarbon($dating, 1975, 5, 21, 22, 32, 11);
  17. }
  18. public function testInstanceFromDateTimeKeepsTimezoneName()
  19. {
  20. $dating = Carbon::instance(\DateTime::createFromFormat('Y-m-d H:i:s', '1975-05-21 22:32:11')->setTimezone(new \DateTimeZone('America/Vancouver')));
  21. $this->assertSame('America/Vancouver', $dating->tzName);
  22. }
  23. public function testInstanceFromDateTimeKeepsMicros()
  24. {
  25. $micro = 254687;
  26. $datetime = \DateTime::createFromFormat('Y-m-d H:i:s.u', '2014-02-01 03:45:27.'.$micro);
  27. $carbon = Carbon::instance($datetime);
  28. $this->assertSame($micro, $carbon->micro);
  29. }
  30. }