コード例 #1
0
ファイル: DateTimeConverter.php プロジェクト: brick/brick
 /**
  * {@inheritdoc}
  */
 public function expand($className, $value, array $options = [])
 {
     try {
         switch ($className) {
             case Duration::class:
                 return Duration::parse($value);
             case LocalDate::class:
                 return LocalDate::parse($value);
             case LocalTime::class:
                 return LocalTime::parse($value);
             case LocalDateTime::class:
                 return LocalDateTime::parse($value);
             case TimeZoneOffset::class:
                 return TimeZoneOffset::parse($value);
             case TimeZoneRegion::class:
                 return TimeZoneRegion::parse($value);
             case YearMonth::class:
                 return YearMonth::parse($value);
             case ZonedDateTime::class:
                 return ZonedDateTime::parse($value);
         }
     } catch (DateTimeParseException $e) {
         throw new ObjectNotConvertibleException($e->getMessage(), $e->getCode(), $e);
     }
     return null;
 }
コード例 #2
0
ファイル: Instant.php プロジェクト: brick/date-time
 /**
  * @param Duration $duration
  *
  * @return Instant
  */
 public function minus(Duration $duration)
 {
     if ($duration->isZero()) {
         return $this;
     }
     return $this->plus($duration->negated());
 }
コード例 #3
0
ファイル: LocalDateTime.php プロジェクト: brick/date-time
 /**
  * Returns a copy of this LocalDateTime with the specific Duration subtracted.
  *
  * @param Duration $duration
  *
  * @return LocalDateTime
  */
 public function minusDuration(Duration $duration)
 {
     return $this->plusDuration($duration->negated());
 }
コード例 #4
0
ファイル: DurationTest.php プロジェクト: brick/date-time
 /**
  * @dataProvider providerToString
  *
  * @param integer $seconds
  * @param integer $nanos
  * @param string  $expected
  */
 public function testToString($seconds, $nanos, $expected)
 {
     $this->assertSame($expected, (string) Duration::ofSeconds($seconds, $nanos));
 }
コード例 #5
0
ファイル: InstantTest.php プロジェクト: brick/date-time
 /**
  * @dataProvider providerPlus
  *
  * @param integer $second         The base second.
  * @param integer $nano           The base nano-of-second.
  * @param integer $plusSeconds    The seconds of the duration to add.
  * @param integer $plusNanos      The nanos of the duration to add.
  * @param integer $expectedSecond The expected second of the result.
  * @param integer $expectedNano   The expected nano of the result.
  */
 public function testMinus($second, $nano, $plusSeconds, $plusNanos, $expectedSecond, $expectedNano)
 {
     $result = Instant::of($second, $nano)->minus(Duration::ofSeconds(-$plusSeconds, -$plusNanos));
     $this->assertReadableInstantIs($expectedSecond, $expectedNano, $result);
 }
コード例 #6
0
ファイル: OffsetClockTest.php プロジェクト: brick/date-time
 /**
  * @dataProvider providerOffsetClock
  *
  * @param integer $second         The epoch second to set the base clock to.
  * @param integer $nano           The nano to set the base clock to.
  * @param string  $duration       A parsable duration string.
  * @param integer $expectedSecond The expected epoch second returned by the clock.
  * @param integer $expectedNano   The expected nano returned by the clock.
  */
 public function testOffsetClock($second, $nano, $duration, $expectedSecond, $expectedNano)
 {
     $baseClock = new FixedClock(Instant::of($second, $nano));
     $clock = new OffsetClock($baseClock, Duration::parse($duration));
     $this->assertReadableInstantIs($expectedSecond, $expectedNano, $clock->getTime());
 }
コード例 #7
0
ファイル: LocalTimeTest.php プロジェクト: brick/date-time
 /**
  * @dataProvider providerDuration
  *
  * @param integer $h  The base hour.
  * @param integer $m  The base minute.
  * @param integer $s  The base second.
  * @param integer $n  The base nano.
  * @param integer $ds The number of seconds in the duration.
  * @param integer $dn The nano adjustment of the duration.
  * @param integer $eh The expected hour of the result time.
  * @param integer $em The expected minute of the result time.
  * @param integer $es The expected second of the result time.
  * @param integer $en The expected nano of the result time.
  */
 public function testMinusDuration($h, $m, $s, $n, $ds, $dn, $eh, $em, $es, $en)
 {
     $localTime = LocalTime::of($h, $m, $s, $n);
     $duration = Duration::ofSeconds(-$ds, -$dn);
     $this->assertLocalTimeIs($eh, $em, $es, $en, $localTime->MinusDuration($duration));
 }
コード例 #8
0
ファイル: LocalDateTimeTest.php プロジェクト: brick/date-time
 /**
  * @dataProvider providerDuration
  *
  * @param integer $ds The seconds of the duration.
  * @param integer $dn The nano adjustment of the duration.
  * @param integer $y  The expected year.
  * @param integer $m  The expected month.
  * @param integer $d  The expected day.
  * @param integer $h  The exepected hour.
  * @param integer $i  The expected minute.
  * @param integer $s  The expected second.
  * @param integer $n  The expected nano.
  */
 public function testMinusDuration($ds, $dn, $y, $m, $d, $h, $i, $s, $n)
 {
     $localDateTime = LocalDate::of(2001, 2, 3)->atTime(LocalTime::of(4, 5, 6, 123456789));
     $duration = Duration::ofSeconds(-$ds, -$dn);
     $this->assertLocalDateTimeIs($y, $m, $d, $h, $i, $s, $n, $localDateTime->minusDuration($duration));
 }
コード例 #9
0
ファイル: AbstractTestCase.php プロジェクト: brick/date-time
 /**
  * @param integer  $seconds  The expected seconds.
  * @param integer  $nanos    The expected nanos.
  * @param Duration $duration The duration to test.
  */
 protected function assertDurationIs($seconds, $nanos, Duration $duration)
 {
     $this->compare([$seconds, $nanos], [$duration->getSeconds(), $duration->getNanos()]);
 }