CreateFromTimeTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 CreateFromTimeTest extends TestFixture
  12. {
  13. public function testCreateFromDateWithDefaults()
  14. {
  15. $d = Carbon::createFromTime();
  16. $this->assertSame($d->timestamp, Carbon::create(null, null, null, null, null, null)->timestamp);
  17. }
  18. public function testCreateFromDate()
  19. {
  20. $d = Carbon::createFromTime(23, 5, 21);
  21. $this->assertCarbon($d, Carbon::now()->year, Carbon::now()->month, Carbon::now()->day, 23, 5, 21);
  22. }
  23. public function testCreateFromTimeWithHour()
  24. {
  25. $d = Carbon::createFromTime(22);
  26. $this->assertSame(22, $d->hour);
  27. $this->assertSame(0, $d->minute);
  28. $this->assertSame(0, $d->second);
  29. }
  30. public function testCreateFromTimeWithMinute()
  31. {
  32. $d = Carbon::createFromTime(null, 5);
  33. $this->assertSame(5, $d->minute);
  34. }
  35. public function testCreateFromTimeWithSecond()
  36. {
  37. $d = Carbon::createFromTime(null, null, 21);
  38. $this->assertSame(21, $d->second);
  39. }
  40. public function testCreateFromTimeWithDateTimeZone()
  41. {
  42. $d = Carbon::createFromTime(12, 0, 0, new \DateTimeZone('Europe/London'));
  43. $this->assertCarbon($d, Carbon::now()->year, Carbon::now()->month, Carbon::now()->day, 12, 0, 0);
  44. $this->assertSame('Europe/London', $d->tzName);
  45. }
  46. public function testCreateFromTimeWithTimeZoneString()
  47. {
  48. $d = Carbon::createFromTime(12, 0, 0, 'Europe/London');
  49. $this->assertCarbon($d, Carbon::now()->year, Carbon::now()->month, Carbon::now()->day, 12, 0, 0);
  50. $this->assertSame('Europe/London', $d->tzName);
  51. }
  52. }