TestsCarbonGettersTest

The Simple Calendar Tests Carbon GettersTest class.

Defined (1)

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

/vendor/nesbot/carbon/tests/Carbon/GettersTest.php  
  1. class GettersTest extends AbstractTestCase 
  2. public function testGettersThrowExceptionOnUnknownGetter() 
  3. $this->setExpectedException('InvalidArgumentException'); 
  4. Carbon::create(1234, 5, 6, 7, 8, 9)->sdfsdfss; 
  5.  
  6. public function testYearGetter() 
  7. $d = Carbon::create(1234, 5, 6, 7, 8, 9); 
  8. $this->assertSame(1234, $d->year); 
  9.  
  10. public function testYearIsoGetter() 
  11. $d = Carbon::createFromDate(2012, 12, 31); 
  12. $this->assertSame(2013, $d->yearIso); 
  13.  
  14. public function testMonthGetter() 
  15. $d = Carbon::create(1234, 5, 6, 7, 8, 9); 
  16. $this->assertSame(5, $d->month); 
  17.  
  18. public function testDayGetter() 
  19. $d = Carbon::create(1234, 5, 6, 7, 8, 9); 
  20. $this->assertSame(6, $d->day); 
  21.  
  22. public function testHourGetter() 
  23. $d = Carbon::create(1234, 5, 6, 7, 8, 9); 
  24. $this->assertSame(7, $d->hour); 
  25.  
  26. public function testMinuteGetter() 
  27. $d = Carbon::create(1234, 5, 6, 7, 8, 9); 
  28. $this->assertSame(8, $d->minute); 
  29.  
  30. public function testSecondGetter() 
  31. $d = Carbon::create(1234, 5, 6, 7, 8, 9); 
  32. $this->assertSame(9, $d->second); 
  33.  
  34. public function testMicroGetter() 
  35. $micro = 345678; 
  36. $d = Carbon::parse('2014-01-05 12:34:11.'.$micro); 
  37. $this->assertSame($micro, $d->micro); 
  38.  
  39. public function testMicroGetterWithDefaultNow() 
  40. $d = Carbon::now(); 
  41. $this->assertSame(0, $d->micro); 
  42.  
  43. public function testDayOfWeeGetter() 
  44. $d = Carbon::create(2012, 5, 7, 7, 8, 9); 
  45. $this->assertSame(Carbon::MONDAY, $d->dayOfWeek); 
  46.  
  47. public function testDayOfYearGetter() 
  48. $d = Carbon::createFromDate(2012, 5, 7); 
  49. $this->assertSame(127, $d->dayOfYear); 
  50.  
  51. public function testDaysInMonthGetter() 
  52. $d = Carbon::createFromDate(2012, 5, 7); 
  53. $this->assertSame(31, $d->daysInMonth); 
  54.  
  55. public function testTimestampGetter() 
  56. $d = Carbon::create(); 
  57. $d->setTimezone('GMT'); 
  58. $this->assertSame(0, $d->setDateTime(1970, 1, 1, 0, 0, 0)->timestamp); 
  59.  
  60. public function testGetAge() 
  61. $d = Carbon::now(); 
  62. $this->assertSame(0, $d->age); 
  63.  
  64. public function testGetAgeWithRealAge() 
  65. $d = Carbon::createFromDate(1975, 5, 21); 
  66. $age = intval(substr(date('Ymd') - date('Ymd', $d->timestamp), 0, -4)); 
  67.  
  68. $this->assertSame($age, $d->age); 
  69.  
  70. public function testGetQuarterFirst() 
  71. $d = Carbon::createFromDate(2012, 1, 1); 
  72. $this->assertSame(1, $d->quarter); 
  73.  
  74. public function testGetQuarterFirstEnd() 
  75. $d = Carbon::createFromDate(2012, 3, 31); 
  76. $this->assertSame(1, $d->quarter); 
  77.  
  78. public function testGetQuarterSecond() 
  79. $d = Carbon::createFromDate(2012, 4, 1); 
  80. $this->assertSame(2, $d->quarter); 
  81.  
  82. public function testGetQuarterThird() 
  83. $d = Carbon::createFromDate(2012, 7, 1); 
  84. $this->assertSame(3, $d->quarter); 
  85.  
  86. public function testGetQuarterFourth() 
  87. $d = Carbon::createFromDate(2012, 10, 1); 
  88. $this->assertSame(4, $d->quarter); 
  89.  
  90. public function testGetQuarterFirstLast() 
  91. $d = Carbon::createFromDate(2012, 12, 31); 
  92. $this->assertSame(4, $d->quarter); 
  93.  
  94. public function testGetLocalTrue() 
  95. // Default timezone has been set to America/Toronto in AbstractTestCase.php 
  96. // @see : http://en.wikipedia.org/wiki/List_of_UTC_time_offsets 
  97. $this->assertTrue(Carbon::createFromDate(2012, 1, 1, 'America/Toronto')->local); 
  98. $this->assertTrue(Carbon::createFromDate(2012, 1, 1, 'America/New_York')->local); 
  99.  
  100. public function testGetLocalFalse() 
  101. $this->assertFalse(Carbon::createFromDate(2012, 7, 1, 'UTC')->local); 
  102. $this->assertFalse(Carbon::createFromDate(2012, 7, 1, 'Europe/London')->local); 
  103.  
  104. public function testGetUtcFalse() 
  105. $this->assertFalse(Carbon::createFromDate(2013, 1, 1, 'America/Toronto')->utc); 
  106. $this->assertFalse(Carbon::createFromDate(2013, 1, 1, 'Europe/Paris')->utc); 
  107.  
  108. public function testGetUtcTrue() 
  109. $this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'Atlantic/Reykjavik')->utc); 
  110. $this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'Europe/Lisbon')->utc); 
  111. $this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'Africa/Casablanca')->utc); 
  112. $this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'Africa/Dakar')->utc); 
  113. $this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'Europe/Dublin')->utc); 
  114. $this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'Europe/London')->utc); 
  115. $this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'UTC')->utc); 
  116. $this->assertTrue(Carbon::createFromDate(2013, 1, 1, 'GMT')->utc); 
  117.  
  118. public function testGetDstFalse() 
  119. $this->assertFalse(Carbon::createFromDate(2012, 1, 1, 'America/Toronto')->dst); 
  120.  
  121. public function testGetDstTrue() 
  122. $this->assertTrue(Carbon::createFromDate(2012, 7, 1, 'America/Toronto')->dst); 
  123.  
  124. public function testOffsetForTorontoWithDST() 
  125. $this->assertSame(-18000, Carbon::createFromDate(2012, 1, 1, 'America/Toronto')->offset); 
  126.  
  127. public function testOffsetForTorontoNoDST() 
  128. $this->assertSame(-14400, Carbon::createFromDate(2012, 6, 1, 'America/Toronto')->offset); 
  129.  
  130. public function testOffsetForGMT() 
  131. $this->assertSame(0, Carbon::createFromDate(2012, 6, 1, 'GMT')->offset); 
  132.  
  133. public function testOffsetHoursForTorontoWithDST() 
  134. $this->assertSame(-5, Carbon::createFromDate(2012, 1, 1, 'America/Toronto')->offsetHours); 
  135.  
  136. public function testOffsetHoursForTorontoNoDST() 
  137. $this->assertSame(-4, Carbon::createFromDate(2012, 6, 1, 'America/Toronto')->offsetHours); 
  138.  
  139. public function testOffsetHoursForGMT() 
  140. $this->assertSame(0, Carbon::createFromDate(2012, 6, 1, 'GMT')->offsetHours); 
  141.  
  142. public function testIsLeapYearTrue() 
  143. $this->assertTrue(Carbon::createFromDate(2012, 1, 1)->isLeapYear()); 
  144.  
  145. public function testIsLeapYearFalse() 
  146. $this->assertFalse(Carbon::createFromDate(2011, 1, 1)->isLeapYear()); 
  147.  
  148. public function testWeekOfMonth() 
  149. $this->assertSame(5, Carbon::createFromDate(2012, 9, 30)->weekOfMonth); 
  150. $this->assertSame(4, Carbon::createFromDate(2012, 9, 28)->weekOfMonth); 
  151. $this->assertSame(3, Carbon::createFromDate(2012, 9, 20)->weekOfMonth); 
  152. $this->assertSame(2, Carbon::createFromDate(2012, 9, 8)->weekOfMonth); 
  153. $this->assertSame(1, Carbon::createFromDate(2012, 9, 1)->weekOfMonth); 
  154.  
  155. public function testWeekOfYearFirstWeek() 
  156. $this->assertSame(52, Carbon::createFromDate(2012, 1, 1)->weekOfYear); 
  157. $this->assertSame(1, Carbon::createFromDate(2012, 1, 2)->weekOfYear); 
  158.  
  159. public function testWeekOfYearLastWeek() 
  160. $this->assertSame(52, Carbon::createFromDate(2012, 12, 30)->weekOfYear); 
  161. $this->assertSame(1, Carbon::createFromDate(2012, 12, 31)->weekOfYear); 
  162.  
  163. public function testGetTimezone() 
  164. $dt = Carbon::createFromDate(2000, 1, 1, 'America/Toronto'); 
  165. $this->assertSame('America/Toronto', $dt->timezone->getName()); 
  166.  
  167. public function testGetTz() 
  168. $dt = Carbon::createFromDate(2000, 1, 1, 'America/Toronto'); 
  169. $this->assertSame('America/Toronto', $dt->tz->getName()); 
  170.  
  171. public function testGetTimezoneName() 
  172. $dt = Carbon::createFromDate(2000, 1, 1, 'America/Toronto'); 
  173. $this->assertSame('America/Toronto', $dt->timezoneName); 
  174.  
  175. public function testGetTzName() 
  176. $dt = Carbon::createFromDate(2000, 1, 1, 'America/Toronto'); 
  177. $this->assertSame('America/Toronto', $dt->tzName); 
  178.  
  179. public function testInvalidGetter() 
  180. $this->setExpectedException('InvalidArgumentException'); 
  181. $d = Carbon::now(); 
  182. $bb = $d->doesNotExit;