/** * @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)); }
/** * @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); }
/** * @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)); }
/** * @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)); }
/** * Returns a Duration representing the time elapsed between two instants. * * A Duration represents a directed distance between two points on the time-line. * As such, this method will return a negative duration if the end is before the start. * * @param \Brick\DateTime\ReadableInstant $startInclusive The start instant, inclusive. * @param \Brick\DateTime\ReadableInstant $endExclusive The end instant, exclusive. * * @return \Brick\DateTime\Duration */ public static function between(ReadableInstant $startInclusive, ReadableInstant $endExclusive) { $startInclusive = $startInclusive->getInstant(); $endExclusive = $endExclusive->getInstant(); $seconds = $endExclusive->getEpochSecond() - $startInclusive->getEpochSecond(); $nanos = $endExclusive->getNano() - $startInclusive->getNano(); return Duration::ofSeconds($seconds, $nanos); }