/** * {@inheritdoc} */ public function getTime() { list($fraction, $epochSecond) = explode(' ', microtime()); $epochSecond = (int) $epochSecond; $nanoAdjustment = 10 * (int) substr($fraction, 2, 8); return Instant::of($epochSecond, $nanoAdjustment); }
/** * {@inheritdoc} */ public function convertToPHPValue($value, AbstractPlatform $platform) { if ($value === null) { return null; } return Instant::of($value); }
/** * @dataProvider providerGetOffset * * @param string $region The time-zone region. * @param integer $epochSecond The instant to test. * @param integer $expectedOffset The expected offset in seconds. */ public function testGetOffset($region, $epochSecond, $expectedOffset) { $actualOffset = TimeZoneRegion::of($region)->getOffset(Instant::of($epochSecond)); $this->assertSame($expectedOffset, $actualOffset); }
/** * @dataProvider providerNow * * @param integer $epochSecond The epoch second. * @param string $timeZone The time-zone. * @param integer $year The expected year. * @param integer $month The expected month. */ public function testNow($epochSecond, $timeZone, $year, $month) { $previousClock = Clock::setDefault(new FixedClock(Instant::of($epochSecond))); $this->assertYearMonthIs($year, $month, YearMonth::now(TimeZone::parse($timeZone))); Clock::setDefault($previousClock); }
public function testGetOffset() { $whateverInstant = Instant::of(123456789, 987654321); $timeZoneOffset = TimeZoneOffset::ofTotalSeconds(-18000); $this->assertSame(-18000, $timeZoneOffset->getOffset($whateverInstant)); }
public function testChangeTimeZone() { $timezone1 = TimeZone::parse('UTC'); $timezone2 = TimeZone::parse('America/Los_Angeles'); $datetime1 = ZonedDateTime::ofInstant(Instant::of(1000000000), $timezone1); $datetime2 = $datetime1->withTimeZoneSameInstant($timezone2); $this->assertSame($timezone1, $datetime1->getTimezone()); $this->assertSame($timezone2, $datetime2->getTimezone()); $this->assertSame('2001-09-08T18:46:40', (string) $datetime2->getDateTime()); $datetime2 = $datetime1->withTimeZoneSameLocal($timezone2); $this->assertSame($timezone1, $datetime1->getTimezone()); $this->assertSame($timezone2, $datetime2->getTimezone()); $this->assertSame('2001-09-09T01:46:40', (string) $datetime2->getDateTime()); }
/** * @dataProvider providerBetween * * @param integer $seconds1 * @param integer $nanos1 * @param integer $seconds2 * @param integer $nanos2 * @param integer $seconds * @param integer $nanos */ public function testBetween($seconds1, $nanos1, $seconds2, $nanos2, $seconds, $nanos) { $i1 = Instant::of($seconds1, $nanos1); $i2 = Instant::of($seconds2, $nanos2); $this->assertDurationIs($seconds, $nanos, Duration::between($i1, $i2)); }
/** * @dataProvider providerToString * * @param integer $epochSecond The epoch second to test. * @param integer $nano The nano adjustment to the epoch second. * @param string $expectedString The expected string output. */ public function testToString($epochSecond, $nano, $expectedString) { $this->assertSame($expectedString, (string) Instant::of($epochSecond, $nano)); }
/** * @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()); }
/** * {@inheritdoc} */ public function getInstant() { return Instant::of($this->dateTime->getTimestamp(), $this->localDateTime->getNano()); }
/** * @dataProvider providerNow * * @param integer $epochSecond The epoch second. * @param string $timeZone The time-zone. * @param integer $month The expected month. * @param integer $day The expected day. */ public function testNow($epochSecond, $timeZone, $month, $day) { $previousClock = Clock::setDefault(new FixedClock(Instant::of($epochSecond))); $this->assertMonthDayIs($month, $day, MonthDay::now(TimeZone::parse($timeZone))); Clock::setDefault($previousClock); }
public function testFixedClock() { $clock = new FixedClock(Instant::of(123456789, 987654321)); $this->assertReadableInstantIs(123456789, 987654321, $clock->getTime()); }
/** * @param integer $epochSecond The epoch second. * @param integer $nanoAdjustment The nanosecond adjustment to the epoch second. */ protected function setClockTime($epochSecond, $nanoAdjustment = 0) { Clock::setDefault(new FixedClock(Instant::of($epochSecond, $nanoAdjustment))); }