TestsCarbonConstructTest

The Simple Calendar Tests Carbon ConstructTest class.

Defined (1)

The class is defined in the following location(s).

/vendor/nesbot/carbon/tests/Carbon/ConstructTest.php  
  1. class ConstructTest extends AbstractTestCase 
  2. public function testCreatesAnInstanceDefaultToNow() 
  3. $c = new Carbon(); 
  4. $now = Carbon::now(); 
  5. $this->assertInstanceOfCarbon($c); 
  6. $this->assertSame($now->tzName, $c->tzName); 
  7. $this->assertCarbon($c, $now->year, $now->month, $now->day, $now->hour, $now->minute, $now->second); 
  8.  
  9. public function testParseCreatesAnInstanceDefaultToNow() 
  10. $c = Carbon::parse(); 
  11. $now = Carbon::now(); 
  12. $this->assertInstanceOfCarbon($c); 
  13. $this->assertSame($now->tzName, $c->tzName); 
  14. $this->assertCarbon($c, $now->year, $now->month, $now->day, $now->hour, $now->minute, $now->second); 
  15.  
  16. public function testWithFancyString() 
  17. $c = new Carbon('first day of January 2008'); 
  18. $this->assertCarbon($c, 2008, 1, 1, 0, 0, 0); 
  19.  
  20. public function testParseWithFancyString() 
  21. $c = Carbon::parse('first day of January 2008'); 
  22. $this->assertCarbon($c, 2008, 1, 1, 0, 0, 0); 
  23.  
  24. public function testDefaultTimezone() 
  25. $c = new Carbon('now'); 
  26. $this->assertSame('America/Toronto', $c->tzName); 
  27.  
  28. public function testParseWithDefaultTimezone() 
  29. $c = Carbon::parse('now'); 
  30. $this->assertSame('America/Toronto', $c->tzName); 
  31.  
  32. public function testSettingTimezone() 
  33. $timezone = 'Europe/London'; 
  34. $dtz = new \DateTimeZone($timezone); 
  35. $dt = new \DateTime('now', $dtz); 
  36. $dayLightSavingTimeOffset = $dt->format('I'); 
  37.  
  38. $c = new Carbon('now', $dtz); 
  39. $this->assertSame($timezone, $c->tzName); 
  40. $this->assertSame(0 + $dayLightSavingTimeOffset, $c->offsetHours); 
  41.  
  42. public function testParseSettingTimezone() 
  43. $timezone = 'Europe/London'; 
  44. $dtz = new \DateTimeZone($timezone); 
  45. $dt = new \DateTime('now', $dtz); 
  46. $dayLightSavingTimeOffset = $dt->format('I'); 
  47.  
  48. $c = Carbon::parse('now', $dtz); 
  49. $this->assertSame($timezone, $c->tzName); 
  50. $this->assertSame(0 + $dayLightSavingTimeOffset, $c->offsetHours); 
  51.  
  52. public function testSettingTimezoneWithString() 
  53. $timezone = 'Asia/Tokyo'; 
  54. $dtz = new \DateTimeZone($timezone); 
  55. $dt = new \DateTime('now', $dtz); 
  56. $dayLightSavingTimeOffset = $dt->format('I'); 
  57.  
  58. $c = new Carbon('now', $timezone); 
  59. $this->assertSame($timezone, $c->tzName); 
  60. $this->assertSame(9 + $dayLightSavingTimeOffset, $c->offsetHours); 
  61.  
  62. public function testParseSettingTimezoneWithString() 
  63. $timezone = 'Asia/Tokyo'; 
  64. $dtz = new \DateTimeZone($timezone); 
  65. $dt = new \DateTime('now', $dtz); 
  66. $dayLightSavingTimeOffset = $dt->format('I'); 
  67.  
  68. $c = Carbon::parse('now', $timezone); 
  69. $this->assertSame($timezone, $c->tzName); 
  70. $this->assertSame(9 + $dayLightSavingTimeOffset, $c->offsetHours);