Пример #1
0
 /**
  * @expectedException \AssertionError
  */
 public function test_that_compare_to_throws_exception_for_invalid_argument()
 {
     $time = Time::create(16, 30, 6);
     $time->compareTo('16:30:06');
 }
Пример #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
 /**
  * Creates instance with a given second
  *
  * @param int $second The second
  *
  * @return DateTime
  *
  * @throws DomainException When the date/time is not valid
  */
 public function withSecond(int $second) : DateTime
 {
     return new static($this->date(), Time::create($this->hour(), $this->minute(), $second), $this->timezone());
 }
Пример #4
0
 public function test_that_with_time_returns_expected_instance()
 {
     $dateTime = DateTime::now();
     $dateTime = $dateTime->withTime(Time::create(12, 0, 0));
     $this->assertSame('12:00:00', $dateTime->time()->toString());
 }
Пример #5
0
 /**
  * @expectedException Novuso\System\Exception\DomainException
  */
 public function test_that_create_throws_exception_for_micro_out_of_range()
 {
     Time::create(16, 30, 6, 3240124);
 }