Changeset 1860

Show
Ignore:
Timestamp:
09/27/08 01:42:51 (3 months ago)
Author:
mikey
Message:

use constructor: throws exception on invalid date strings instead of creating a DateTime? instance denoting the current date

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • framework/trunk/src/main/php/net/stubbles/lang/types/stubDate.php

    r1858 r1860  
    6262            } 
    6363        } elseif (is_string($dateTime) === true) { 
    64             if (null === $timeZone) { 
    65                 $this->dateTime = date_create($dateTime); 
    66             } else { 
    67                 $this->dateTime = date_create($dateTime, $timeZone->getHandle()); 
     64            try { 
     65                if (null === $timeZone) { 
     66                    $this->dateTime = new DateTime($dateTime); 
     67                } else { 
     68                    $this->dateTime = new DateTime($dateTime, $timeZone->getHandle()); 
     69                } 
     70            } catch (Exception $e) { 
     71                throw new stubIllegalArgumentException('Given datetime string ' . $dateTime . ' is not a valid date string.'); 
    6872            } 
    6973        } else { 
  • framework/trunk/src/test/php/net/stubbles/lang/types/stubDateTestCase.php

    r1858 r1860  
    413413        $date = new stubDate(null); 
    414414    } 
     415 
     416    /** 
     417     * failing constructoon throws a illegal argument exception 
     418     * 
     419     * @test 
     420     * @expectedException  stubIllegalArgumentException 
     421     */ 
     422    public function invalidDateStringhrowsIllegalArgumentException() 
     423    { 
     424        $date = new stubDate('invalid'); 
     425    } 
    415426} 
    416427?>