Changeset 1858
- Timestamp:
- 09/27/08 00:38:37 (3 months ago)
- Files:
-
- framework/trunk/src/main/php/net/stubbles/lang/types/stubDate.php (modified) (1 diff)
- framework/trunk/src/main/php/net/stubbles/lang/types/stubTimeZone.php (modified) (2 diffs)
- framework/trunk/src/test/php/net/stubbles/lang/types/stubDateTestCase.php (modified) (2 diffs)
- framework/trunk/src/test/php/net/stubbles/lang/types/stubTimeZoneTestCase.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
framework/trunk/src/main/php/net/stubbles/lang/types/stubDate.php
r1853 r1858 83 83 public static function now() 84 84 { 85 return new self( );85 return new self(time()); 86 86 } 87 87 framework/trunk/src/main/php/net/stubbles/lang/types/stubTimeZone.php
r1855 r1858 42 42 { 43 43 if (is_string($timeZone) === true) { 44 $this->timeZone = timezone_open($timeZone);44 $this->timeZone = @timezone_open($timeZone); 45 45 } elseif (null === $timeZone) { 46 46 $this->timeZone = timezone_open(date_default_timezone_get()); … … 101 101 { 102 102 if (null === $date) { 103 $this->timeZone->getOffset(new DateTime('now'));103 return $this->timeZone->getOffset(new DateTime('now')); 104 104 } 105 105 framework/trunk/src/test/php/net/stubbles/lang/types/stubDateTestCase.php
r1853 r1858 11 11 stubClassLoader::load('net::stubbles::lang::types::stubDate'); 12 12 /** 13 * Helper class for the test. 14 * 15 * @package stubbles 16 * @subpackage lang_types_test 17 */ 18 class DateHandleDeliverer extends stubDate 19 { 20 /** 21 * returns handle 22 * 23 * @return DateTime 24 */ 25 public static function deliverHandle(stubDate $date) 26 { 27 return $date->dateTime; 28 } 29 } 30 /** 13 31 * Tests for net::stubbles::lang::types::stubTimeZone. 14 32 * … … 330 348 $this->assertEquals('2007-11-10 19:15:00+0000', $date->format('Y-m-d H:i:sO', new stubTimeZone())); 331 349 } 350 351 /** 352 * now() constructs date with current time 353 * 354 * @test 355 */ 356 public function nowConstructsCurrentDate() 357 { 358 $date = stubDate::now(); 359 $this->assertType('stubDate', $date); 360 $this->assertLessThanOrEqual(time(), $date->getTimestamp()); 361 } 362 363 /** 364 * single date and time parts should be returned 365 * 366 * @test 367 */ 368 public function partsReturned() 369 { 370 // 2007-08-23T12:35:47+00:00 371 $date = new stubDate(1187872547); 372 $this->assertEquals(47, $date->getSeconds()); 373 $this->assertEquals(35, $date->getMinutes()); 374 $this->assertEquals(12, $date->getHours()); 375 $this->assertEquals(23, $date->getDay()); 376 $this->assertEquals(8, $date->getMonth()); 377 $this->assertEquals(2007, $date->getYear()); 378 } 379 380 /** 381 * same dates should be equal 382 * 383 * @test 384 */ 385 public function sameDatesShouldBeEqual() 386 { 387 $date = new stubDate('31.12.1969 00:00 GMT'); 388 $this->assertFalse($date->equals('foo')); 389 $this->assertTrue($date->equals(new stubDate('1969-12-31T00:00:00+00:00'))); 390 $this->assertFalse($date->equals(new stubDate('1969-12-01T00:00:00+00:00'))); 391 } 392 393 /** 394 * handle must be cloned as well 395 * 396 * @test 397 */ 398 public function cloneClonesHandleAsWell() 399 { 400 $date = new stubDate('31.12.1969 00:00 GMT'); 401 $clonedDate = clone $date; 402 $this->assertNotSame(DateHandleDeliverer::deliverHandle($date), DateHandleDeliverer::deliverHandle($clonedDate)); 403 } 404 405 /** 406 * failing constructoon throws a illegal argument exception 407 * 408 * @test 409 * @expectedException stubIllegalArgumentException 410 */ 411 public function failingConstructionThrowsIllegalArgumentException() 412 { 413 $date = new stubDate(null); 414 } 332 415 } 333 416 ?> framework/trunk/src/test/php/net/stubbles/lang/types/stubTimeZoneTestCase.php
r1853 r1858 68 68 69 69 /** 70 * offset in seconds for current date is 0 seconds or 7200 seconds, depending 71 * whether we are in dst or not 72 * 73 * @test 74 */ 75 public function offsetForCurrentDateIs0SecondsOr7200SecondsDependingWhetherInDstOrNot() 76 { 77 $offset = $this->timeZone->getOffsetInSeconds(); 78 $this->assertTrue((0 === $offset || 7200 === $offset)); 79 } 80 81 /** 70 82 * offset for some time zones is just an half hour more 71 83 * … … 99 111 $this->assertEquals(new stubDate('2006-12-31 14:00:00 Europe/Berlin'), $this->timeZone->translate($date)); 100 112 } 113 114 /** 115 * a time zone with dst should be marked as such 116 * 117 * @test 118 */ 119 public function timeZonesHavingDstShouldBeMarkedAsSuch() 120 { 121 $this->assertTrue($this->timeZone->hasDst()); 122 } 123 124 /** 125 * timezone instances are equal if they represent the same timezone 126 * 127 * @test 128 */ 129 public function timeZonesAreEqualsIfTheyRepresentTheSameTimeZoneString() 130 { 131 $this->assertTrue($this->timeZone->equals($this->timeZone)); 132 $this->assertTrue($this->timeZone->equals(new stubTimeZone('Europe/Berlin'))); 133 $this->assertFalse($this->timeZone->equals(new stubTimeZone('Australia/Adelaide'))); 134 $this->assertFalse($this->timeZone->equals(new stdClass())); 135 } 136 137 /** 138 * illegal time zone value throws illegal argument exception 139 * 140 * @test 141 * @expectedException stubIllegalArgumentException 142 */ 143 public function invalidTimeZoneValueThrowsIllegalArgumentExceptionOnConstruction() 144 { 145 $timeZone = new stubTimeZone(500); 146 } 147 148 /** 149 * non existing time zone value throws illegal argument exception 150 * 151 * @test 152 * @expectedException stubIllegalArgumentException 153 */ 154 public function nonExistingTimeZoneValueThrowsIllegalArgumentExceptionOnConstruction() 155 { 156 $timeZone = new stubTimeZone('Europe/Karlsruhe'); 157 } 101 158 } 102 159 ?>
