예제 #1
0
파일: DateTest.php 프로젝트: novuso/common
 /**
  * @expectedException \AssertionError
  */
 public function test_that_compare_to_throws_exception_for_invalid_argument()
 {
     $date = Date::create(2015, 6, 20);
     $date->compareTo('2015-06-20');
 }
예제 #2
0
 /**
  * Creates instance from a date/time string
  *
  * @param string $dateTime The date/time string
  *
  * @return DateTime
  *
  * @throws DomainException When the string is invalid
  */
 public static function fromString($dateTime)
 {
     assert(Test::isString($dateTime), sprintf('%s expects $dateTime to be a string; received (%s) %s', __METHOD__, gettype($dateTime), VarPrinter::toString($dateTime)));
     $pattern = sprintf('/\\A%s-%s-%sT%s:%s:%s\\.%s\\[%s\\]\\z/', '(?P<year>[\\d]{4})', '(?P<month>[\\d]{2})', '(?P<day>[\\d]{2})', '(?P<hour>[\\d]{2})', '(?P<minute>[\\d]{2})', '(?P<second>[\\d]{2})', '(?P<micro>[\\d]{6})', '(?P<timezone>.+)');
     if (!preg_match($pattern, $dateTime, $matches)) {
         $message = sprintf('%s expects $dateTime in "Y-m-d\\TH:i:s.u[timezone]" format', __METHOD__);
         throw DomainException::create($message);
     }
     $year = (int) $matches['year'];
     $month = (int) $matches['month'];
     $day = (int) $matches['day'];
     $hour = (int) $matches['hour'];
     $minute = (int) $matches['minute'];
     $second = (int) $matches['second'];
     $micro = (int) $matches['micro'];
     $timezone = $matches['timezone'];
     return new self(Date::create($year, $month, $day), Time::create($hour, $minute, $second, $micro), Timezone::create($timezone));
 }
예제 #3
0
파일: DateTime.php 프로젝트: novuso/common
 /**
  * Creates instance with a given day
  *
  * @param int $day The day
  *
  * @return DateTime
  *
  * @throws DomainException When the date/time is not valid
  */
 public function withDay(int $day) : DateTime
 {
     return new static(Date::create($this->year(), $this->month(), $day), $this->time(), $this->timezone());
 }
예제 #4
0
 public function test_that_with_date_returns_expected_instance()
 {
     $dateTime = DateTime::now();
     $dateTime = $dateTime->withDate(Date::create(2016, 1, 1));
     $this->assertSame('2016-01-01', $dateTime->date()->toString());
 }
예제 #5
0
 /**
  * @expectedException Novuso\System\Exception\DomainException
  */
 public function test_that_create_throws_exception_for_invalid_date()
 {
     Date::create(2015, 2, 30);
 }