public function equals($obj) { if ($obj instanceof FixedClock) { return $this->instant->equals($obj->instant) && $this->zone->equals($obj->zone); } return false; }
public function test_constant_UTC() { $test = ZoneOffset::UTC(); $this->assertEquals($test->getId(), "Z"); $this->assertEquals($test->getDisplayName(TextStyle::FULL(), Locale::UK()), "Z"); $this->assertEquals($test->getRules()->isFixedOffset(), true); $this->assertEquals($test->getRules()->getOffset(Instant::ofEpochSecond(0)), ZoneOffset::UTC()); $this->checkOffset($test->getRules(), $this->createLDT(2008, 6, 30), ZoneOffset::UTC(), 1); }
private function run($argv) { $ids = ZoneRulesProvider::getAvailableZoneIds(); $start = Instant::now(); foreach ($ids as $id) { TZDBZoneRulesProvider::getRules($id, false); } $end = Instant::now(); echo 'First run: ', ChronoUnit::MILLIS()->between($start, $end), "ms, count: ", count($ids), "\n"; }
public function instant() { if ($this->tickNanos % 1000000 == 0) { $millis = $this->baseClock->millis(); return Instant::ofEpochMilli($millis - Math::floorMod($millis, $this->tickNanos / 1000000)); } $instant = $this->baseClock->instant(); $nanos = $instant->getNano(); $adjust = Math::floorMod($nanos, $this->tickNanos); return $instant->minusNanos($adjust); }
public function format(DateTimePrintContext $context, &$buf) { /** @var ZoneID $zone */ $zone = $context->getValue(TemporalQueries::zoneId()); if ($zone === null) { return false; } $zname = $zone->getId(); if (!$zone instanceof ZoneOffset) { $dt = $context->getTemporal(); $name = $this->getDisplayName($zname, $dt->isSupported(ChronoField::INSTANT_SECONDS()) ? $zone->getRules()->isDaylightSavings(Instant::from($dt)) ? self::$DST : self::$STD : self::$GENERIC, $context->getLocale()); if ($name !== null) { $zname = $name; } } $buf .= $zname; return true; }
/** * Normalizes the time-zone ID, returning a {@code ZoneOffset} where possible. * <p> * The returns a normalized {@code ZoneId} that can be used in place of this ID. * The result will have {@code ZoneRules} equivalent to those returned by this object, * however the ID returned by {@code getId()} may be different. * <p> * The normalization checks if the rules of this {@code ZoneId} have a fixed offset. * If they do, then the {@code ZoneOffset} equal to that offset is returned. * Otherwise {@code this} is returned. * * @return ZoneId the time-zone unique ID, not null */ public function normalized() { try { $rules = $this->getRules(); if ($rules->isFixedOffset()) { return $rules->getOffset(Instant::EPOCH()); } } catch (ZoneRulesException $ex) { // invalid ZoneRegion is not important to this method } return $this; }
public function test_factory_ofInstant_minYear() { $test = OffsetTime::ofInstant(Instant::MIN(), ZoneOffset::UTC()); $this->assertEquals($test->getHour(), 0); $this->assertEquals($test->getMinute(), 0); $this->assertEquals($test->getSecond(), 0); $this->assertEquals($test->getNano(), 0); }
function data_format_withZone_withChronology() { $ym = YearMonth::of(2008, 6); $ld = LocalDate::of(2008, 6, 30); $lt = LocalTime::of(11, 30); $ldt = LocalDateTime::of(2008, 6, 30, 11, 30); $ot = OffsetTime::ofLocalTime(LocalTime::of(11, 30), self::OFFSET_PONE()); $odt = OffsetDateTime::ofDateTime(LocalDateTime::of(2008, 6, 30, 11, 30), self::OFFSET_PONE()); $zdt = ZonedDateTime::ofDateTime(LocalDateTime::of(2008, 6, 30, 11, 30), self::ZONE_PARIS()); $thaiZdt = ThaiBuddhistChronology::INSTANCE()->zonedDateTimeFrom($zdt); $instant = Instant::ofEpochSecond(3600); return [[null, null, DayOfWeek::MONDAY(), "::::"], [null, null, $ym, "2008::::ISO"], [null, null, $ld, "2008::::ISO"], [null, null, $lt, ":11:::"], [null, null, $ldt, "2008:11:::ISO"], [null, null, $ot, ":11:+01:00::"], [null, null, $odt, "2008:11:+01:00::ISO"], [null, null, $zdt, "2008:11:+02:00:Europe/Paris:ISO"], [null, null, $instant, "::::"], [IsoChronology::INSTANCE(), null, DayOfWeek::MONDAY(), "::::ISO"], [IsoChronology::INSTANCE(), null, $ym, "2008::::ISO"], [IsoChronology::INSTANCE(), null, $ld, "2008::::ISO"], [IsoChronology::INSTANCE(), null, $lt, ":11:::ISO"], [IsoChronology::INSTANCE(), null, $ldt, "2008:11:::ISO"], [IsoChronology::INSTANCE(), null, $ot, ":11:+01:00::ISO"], [IsoChronology::INSTANCE(), null, $odt, "2008:11:+01:00::ISO"], [IsoChronology::INSTANCE(), null, $zdt, "2008:11:+02:00:Europe/Paris:ISO"], [IsoChronology::INSTANCE(), null, $instant, "::::ISO"], [null, self::ZONE_PARIS(), DayOfWeek::MONDAY(), ":::Europe/Paris:"], [null, self::ZONE_PARIS(), $ym, "2008:::Europe/Paris:ISO"], [null, self::ZONE_PARIS(), $ld, "2008:::Europe/Paris:ISO"], [null, self::ZONE_PARIS(), $lt, ":11::Europe/Paris:"], [null, self::ZONE_PARIS(), $ldt, "2008:11::Europe/Paris:ISO"], [null, self::ZONE_PARIS(), $ot, ":11:+01:00:Europe/Paris:"], [null, self::ZONE_PARIS(), $odt, "2008:12:+02:00:Europe/Paris:ISO"], [null, self::ZONE_PARIS(), $zdt, "2008:11:+02:00:Europe/Paris:ISO"], [null, self::ZONE_PARIS(), $instant, "1970:02:+01:00:Europe/Paris:ISO"], [null, self::OFFSET_PTHREE(), DayOfWeek::MONDAY(), ":::+03:00:"], [null, self::OFFSET_PTHREE(), $ym, "2008:::+03:00:ISO"], [null, self::OFFSET_PTHREE(), $ld, "2008:::+03:00:ISO"], [null, self::OFFSET_PTHREE(), $lt, ":11::+03:00:"], [null, self::OFFSET_PTHREE(), $ldt, "2008:11::+03:00:ISO"], [null, self::OFFSET_PTHREE(), $ot, null], [null, self::OFFSET_PTHREE(), $odt, "2008:13:+03:00:+03:00:ISO"], [null, self::OFFSET_PTHREE(), $zdt, "2008:12:+03:00:+03:00:ISO"], [null, self::OFFSET_PTHREE(), $instant, "1970:04:+03:00:+03:00:ISO"], [ThaiBuddhistChronology::INSTANCE(), null, DayOfWeek::MONDAY(), null], [ThaiBuddhistChronology::INSTANCE(), null, $ym, null], [ThaiBuddhistChronology::INSTANCE(), null, $ld, "2551::::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $lt, ":11:::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $ldt, "2551:11:::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $ot, ":11:+01:00::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $odt, "2551:11:+01:00::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $zdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $instant, "::::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, DayOfWeek::MONDAY(), null], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $ym, null], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $ld, "2551:::Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $lt, ":11::Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $ldt, "2551:11::Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $ot, ":11:+01:00:Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $odt, "2551:12:+02:00:Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $zdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $instant, "2513:02:+01:00:Europe/Paris:ThaiBuddhist"], [null, self::ZONE_PARIS(), $thaiZdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $thaiZdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"], [IsoChronology::INSTANCE(), self::ZONE_PARIS(), $thaiZdt, "2008:11:+02:00:Europe/Paris:ISO"]]; }
public function test_factory_ofInstant_Instant_nullZone() { TestHelper::assertNullException($this, function () { ZonedDateTime::ofInstant(Instant::EPOCH(), null); }); }
/** * @dataProvider data_instantNoZone */ public function test_parse_instantNoZone_Instant(DateTimeFormatter $formatter, $text, Instant $expected) { $actual = $formatter->parse($text); $this->assertEquals(Instant::from($actual), $expected); }
/** * @group long */ public function test_now_Clock_allSecsInDay_beforeEpoch() { for ($i = -1; $i >= -(2 * 24 * 60 * 60); $i--) { $instant = Instant::ofEpochSecond($i); $clock = Clock::fixed($instant, ZoneOffset::UTC()); $test = LocalDate::nowOf($clock); $this->assertEquals($test->getYear(), 1969); $this->assertEquals($test->getMonth(), Month::DECEMBER()); $this->assertEquals($test->getDayOfMonth(), $i >= -24 * 60 * 60 ? 31 : 30); } }
public function test_parse_fromField_InstantSeconds_NanoOfSecond() { $fmt = (new DateTimeFormatterBuilder())->appendValue(ChronoField::INSTANT_SECONDS())->appendLiteral('.')->appendValue(ChronoField::NANO_OF_SECOND())->toFormatter(); $acc = $fmt->parse("86402.123456789"); $expected = Instant::ofEpochSecond(86402, 123456789); $this->assertEquals($acc->isSupported(ChronoField::INSTANT_SECONDS()), true); $this->assertEquals($acc->isSupported(ChronoField::NANO_OF_SECOND()), true); $this->assertEquals($acc->isSupported(ChronoField::MICRO_OF_SECOND()), true); $this->assertEquals($acc->isSupported(ChronoField::MILLI_OF_SECOND()), true); $this->assertEquals($acc->getLong(ChronoField::INSTANT_SECONDS()), 86402); $this->assertEquals($acc->getLong(ChronoField::NANO_OF_SECOND()), 123456789); $this->assertEquals($acc->getLong(ChronoField::MICRO_OF_SECOND()), 123456); $this->assertEquals($acc->getLong(ChronoField::MILLI_OF_SECOND()), 123); $this->assertEquals(Instant::from($acc), $expected); }
/** * @inheritdoc */ public function toInstant(ZoneOffset $offset) { return Instant::ofEpochSecond($this->toEpochSecond($offset), $this->toLocalTime()->getNano()); }
/** * Obtains an instance of {@code ZonedDateTime} using seconds from the * epoch of 1970-01-01T00:00:00Z. * * @param int $epochSecond the number of seconds from the epoch of 1970-01-01T00:00:00Z * @param int $nanoOfSecond the nanosecond within the second, from 0 to 999,999,999 * @param ZoneId $zone the time-zone, not null * @return ZonedDateTime the zoned date-time, not null * @throws DateTimeException if the result exceeds the supported range */ private static function create($epochSecond, $nanoOfSecond, ZoneId $zone) { $rules = $zone->getRules(); $instant = Instant::ofEpochSecond($epochSecond, $nanoOfSecond); // TODO: rules should be queryable by epochSeconds $offset = $rules->getOffset($instant); $ldt = LocalDateTime::ofEpochSecond($epochSecond, $nanoOfSecond, $offset); return new ZonedDateTime($ldt, $offset, $zone); }
public function test_now_Clock_min() { $clock = Clock::fixed(Instant::MIN(), ZoneOffset::UTC()); $test = LocalTime::nowOf($clock); $this->assertEquals($test->getHour(), 0); $this->assertEquals($test->getMinute(), 0); $this->assertEquals($test->getSecond(), 0); $this->assertEquals($test->getNano(), 0); }
public function zonedDateTimeFrom(TemporalAccessor $temporal) { try { $zone = ZoneId::from($temporal); try { $instant = Instant::from($temporal); return $this->zonedDateTime($instant, $zone); } catch (DateTimeException $ex1) { $cldt = ChronoLocalDateTimeImpl::ensureValid($this, $this->localDateTime($temporal)); return ChronoZonedDateTimeImpl::ofBest($cldt, $zone, null); } } catch (DateTimeException $ex) { throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " . get_class($temporal), $ex); } }
public function instant() { return Instant::ofEpochMilli($this->millis()); }
/** * @dataProvider data_offsetBasedValidPrefix */ public function test_factory_of_String_offsetBasedValid_prefixUT($input, $id, $offsetId) { $test = ZoneId::of("UT" . $input); $this->assertEquals($test->getId(), "UT" . $id); $this->assertEquals($test->getRules(), ZoneOffset::of($offsetId)->getRules()); $this->assertEquals($test->normalized(), ZoneOffset::of($offsetId)); $this->assertEquals($test->getRules()->isFixedOffset(), true); $this->assertEquals($test->getRules()->getOffset(Instant::EPOCH()), ZoneOffset::of($offsetId)); if (defined('HHVM_VERSION')) { $this->markTestSkipped('See https://github.com/facebook/hhvm/issues/6852'); } $this->assertEquals($test->getDisplayName(TextStyle::FULL(), Locale::UK()), $this->displayName("UT" . $id)); }
/** * @expectedException \Celest\DateTimeException */ public function test_until_invalidType() { $odt = OffsetDateTime::of(2010, 6, 30, 1, 1, 1, 0, self::OFFSET_PONE()); $odt->until(Instant::ofEpochSecond(12), CU::SECONDS()); }
private function resolveInstantFields0(ZoneId $selectedZone) { $instant = Instant::ofEpochSecond($this->fieldValues->remove(CF::INSTANT_SECONDS())); $zdt = $this->chrono->zonedDateTime($instant, $selectedZone); $this->updateCheckConflict1($zdt->toLocalDate()); $this->updateCheckConflict3(CF::INSTANT_SECONDS(), CF::SECOND_OF_DAY(), $zdt->toLocalTime()->toSecondOfDay()); }
public function test_factory_between__TemporalTemporal_endNull() { TestHelper::assertNullException($this, function () { $start = Instant::ofEpochSecond(1); Duration::between($start, null); }); }
/** * Gets the previous transition before the specified instant. * <p> * This returns details of the previous transition after the specified instant. * For example, if the instant represents a point where "summer" daylight saving time * applies, then the method will return the transition from the previous "winter" time. * * @param Instant|null $instant the instant to get the previous transition after, not null, but null * may be ignored if the rules have a single offset for all instants * @return ZoneOffsetTransition the previous transition after the specified instant, null if this is before the first transition */ public function previousTransition($instant) { if (empty($this->savingsInstantTransitions)) { return null; } $epochSec = $instant->getEpochSecond(); if ($instant->getNano() > 0 && $epochSec < Long::MAX_VALUE) { $epochSec += 1; // allow rest of method to only use seconds } // check if using last rules $lastHistoric = $this->savingsInstantTransitions[count($this->savingsInstantTransitions) - 1]; if (!empty($this->lastRules) && $epochSec > $lastHistoric) { // search year the instant is in $lastHistoricOffset = $this->wallOffsets[count($this->wallOffsets) - 1]; $year = $this->findYear($epochSec, $lastHistoricOffset); $transArray = $this->findTransitionArray($year); for ($i = count($transArray) - 1; $i >= 0; $i--) { if ($epochSec > $transArray[$i]->toEpochSecond()) { return $transArray[$i]; } } // use last from preceding year $lastHistoricYear = $this->findYear($lastHistoric, $lastHistoricOffset); if (--$year > $lastHistoricYear) { $transArray = $this->findTransitionArray($year); return $transArray[count($transArray) - 1]; } // drop through } // using historic rules $index = Math::binarySearch($this->savingsInstantTransitions, $epochSec); if ($index < 0) { $index = -$index - 1; } if ($index <= 0) { return null; } return ZoneOffsetTransition::ofEpoch($this->savingsInstantTransitions[$index - 1], $this->wallOffsets[$index - 1], $this->wallOffsets[$index]); }
/** * Calculates the amount of time until another instant in terms of the specified unit. * <p> * This calculates the amount of time between two {@code Instant} * objects in terms of a single {@code TemporalUnit}. * The start and end points are {@code this} and the specified instant. * The result will be negative if the end is before the start. * The calculation returns a whole number, representing the number of * complete units between the two instants. * The {@code Temporal} passed to this method is converted to a * {@code Instant} using {@link #from(TemporalAccessor)}. * For example, the amount in days between two dates can be calculated * using {@code startInstant.until(endInstant, SECONDS)}. * <p> * There are two equivalent ways of using this method. * The first is to invoke this method. * The second is to use {@link TemporalUnit#between(Temporal, Temporal)}: * <pre> * // these two lines are equivalent * amount = start.until(end, SECONDS); * amount = SECONDS.between(start, end); * </pre> * The choice should be made based on which makes the code more readable. * <p> * The calculation is implemented in this method for {@link ChronoUnit}. * The units {@code NANOS}, {@code MICROS}, {@code MILLIS}, {@code SECONDS}, * {@code MINUTES}, {@code HOURS}, {@code HALF_DAYS} and {@code DAYS} * are supported. Other {@code ChronoUnit} values will throw an exception. * <p> * If the unit is not a {@code ChronoUnit}, then the result of this method * is obtained by invoking {@code TemporalUnit.between(Temporal, Temporal)} * passing {@code this} as the first argument and the converted input temporal * as the second argument. * <p> * This instance is immutable and unaffected by this method call. * * @param Temporal $endExclusive the end date, exclusive, which is converted to an Instant {@code Instant}, not null * @param TemporalUnit $unit the unit to measure the amount in, not null * @return int the amount of time between this instant and the end instant * @throws DateTimeException if the amount cannot be calculated, or the end * temporal cannot be converted to an Instant {@code Instant} * @throws UnsupportedTemporalTypeException if the unit is not supported * @throws ArithmeticException if numeric overflow occurs */ public function until(Temporal $endExclusive, TemporalUnit $unit) { $end = Instant::from($endExclusive); if ($unit instanceof ChronoUnit) { $f = $unit; switch ($f) { case ChronoUnit::NANOS(): return $this->nanosUntil($end); case ChronoUnit::MICROS(): return Math::div($this->nanosUntil($end), 1000); case ChronoUnit::MILLIS(): return Math::subtractExact($end->toEpochMilli(), $this->toEpochMilli()); case ChronoUnit::SECONDS(): return $this->secondsUntil($end); case ChronoUnit::MINUTES(): return Math::div($this->secondsUntil($end), LocalTime::SECONDS_PER_MINUTE); case ChronoUnit::HOURS(): return Math::div($this->secondsUntil($end), LocalTime::SECONDS_PER_HOUR); case ChronoUnit::HALF_DAYS(): return Math::div($this->secondsUntil($end), 12 * LocalTime::SECONDS_PER_HOUR); case ChronoUnit::DAYS(): return Math::div($this->secondsUntil($end), LocalTime::SECONDS_PER_DAY); } throw new UnsupportedTemporalTypeException("Unsupported unit: " . $unit); } return $unit->between($this, $end); }
/** * @inheritdoc */ public function toInstant() { return Instant::ofEpochSecond($this->toEpochSecond(), $this->toLocalTime()->getNano()); }
public function test_parse_leapSecond() { $expected = OffsetDateTime::of(1970, 2, 3, 23, 59, 59, 123456789, ZoneOffset::UTC())->toInstant(); $f = (new DateTimeFormatterBuilder())->appendInstant4(-1)->toFormatter(); foreach (ResolverStyle::values() as $style) { $pared = $f->withResolverStyle($style)->parse("1970-02-03T23:59:60.123456789Z"); $this->assertEquals($pared->query(Instant::fromQuery()), $expected); $this->assertEquals($pared->query(DateTimeFormatter::parsedExcessDays()), Period::ZERO()); $this->assertEquals($pared->query(DateTimeFormatter::parsedLeapSecond()), true); } }
private static function adjust(TemporalAccessor $temporal, DateTimeFormatter $formatter) { // normal case first (early return is an optimization) $overrideChrono = $formatter->getChronology(); $overrideZone = $formatter->getZone(); if ($overrideChrono == null && $overrideZone == null) { return $temporal; } // ensure minimal change (early return is an optimization) $temporalChrono = $temporal->query(TemporalQueries::chronology()); $temporalZone = $temporal->query(TemporalQueries::zoneId()); if ($temporalChrono !== null && $temporalChrono->equals($overrideChrono)) { $overrideChrono = null; } if ($temporalZone !== null && $temporalZone->equals($overrideZone)) { $overrideZone = null; } if ($overrideChrono === null && $overrideZone === null) { return $temporal; } // make adjustment $effectiveChrono = $overrideChrono != null ? $overrideChrono : $temporalChrono; if ($overrideZone != null) { // if have zone and instant, calculation is simple, defaulting chrono if necessary if ($temporal->isSupported(ChronoField::INSTANT_SECONDS())) { $chrono = $effectiveChrono != null ? $effectiveChrono : IsoChronology::INSTANCE(); return $chrono->zonedDateTime(Instant::from($temporal), $overrideZone); } // block changing zone on OffsetTime, and similar problem cases if ($overrideZone->normalized() instanceof ZoneOffset && $temporal->isSupported(ChronoField::OFFSET_SECONDS()) && $temporal->get(ChronoField::OFFSET_SECONDS()) != $overrideZone->getRules()->getOffset(Instant::EPOCH())->getTotalSeconds()) { throw new DateTimeException("Unable to apply override zone '" . $overrideZone . "' because the temporal object being formatted has a different offset but" . " does not represent an instant: " . $temporal); } } $effectiveZone = $overrideZone !== null ? $overrideZone : $temporalZone; $effectiveDate = null; if ($overrideChrono !== null) { if ($temporal->isSupported(ChronoField::EPOCH_DAY())) { $effectiveDate = $effectiveChrono->dateFrom($temporal); } else { // check for date fields other than epoch-day, ignoring case of converting null to ISO if (!($overrideChrono == IsoChronology::INSTANCE() && $temporalChrono === null)) { foreach (ChronoField::values() as $f) { if ($f->isDateBased() && $temporal->isSupported($f)) { throw new DateTimeException("Unable to apply override chronology '" . $overrideChrono . "' because the temporal object being formatted contains date fields but" . " does not represent a whole date: " . $temporal); } } } $effectiveDate = null; } } else { $effectiveDate = null; } // combine available data // this is a non-standard temporal that is almost a pure delegate // this better handles map-like underlying temporal instances return new Test($effectiveDate, $temporal, $effectiveZone, $effectiveChrono); }
/** * Returns a copy of this date-time with the specified field set to a new value. * <p> * This returns an {@code OffsetDateTime}, based on this one, with the value * for the specified field changed. * This can be used to change any supported field, such as the year, month or day-of-month. * If it is not possible to set the value, because the field is not supported or for * some other reason, an exception is thrown. * <p> * In some cases, changing the specified field can cause the resulting date-time to become invalid, * such as changing the month from 31st January to February would make the day-of-month invalid. * In cases like this, the field is responsible for resolving the date. Typically it will choose * the previous valid date, which would be the last valid day of February in this example. * <p> * If the field is a {@link ChronoField} then the adjustment is implemented here. * <p> * The {@code INSTANT_SECONDS} field will return a date-time with the specified instant. * The offset and nano-of-second are unchanged. * If the new instant value is outside the valid range then a {@code DateTimeException} will be thrown. * <p> * The {@code OFFSET_SECONDS} field will return a date-time with the specified offset. * The local date-time is unaltered. If the new offset value is outside the valid range * then a {@code DateTimeException} will be thrown. * <p> * The other {@link #isSupported(TemporalField) supported fields} will behave as per * the matching method on {@link LocalDateTime#with(TemporalField, long) LocalDateTime}. * In this case, the offset is not part of the calculation and will be unchanged. * <p> * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. * <p> * If the field is not a {@code ChronoField}, then the result of this method * is obtained by invoking {@code TemporalField.adjustInto(Temporal, long)} * passing {@code this} as the argument. In this case, the field determines * whether and how to adjust the instant. * <p> * This instance is immutable and unaffected by this method call. * * @param TemporalField $field the field to set in the result, not null * @param int $newValue the new value of the field in the result * @return OffsetDateTime an {@code OffsetDateTime} based on {@code this} with the specified field set, not null * @throws DateTimeException if the field cannot be set * @throws UnsupportedTemporalTypeException if the field is not supported * @throws ArithmeticException if numeric overflow occurs */ public function with(TemporalField $field, $newValue) { if ($field instanceof ChronoField) { $f = $field; switch ($f) { case ChronoField::INSTANT_SECONDS(): return $this->ofInstant(Instant::ofEpochSecond($newValue, $this->getNano()), $this->offset); case ChronoField::OFFSET_SECONDS(): return $this->_with($this->dateTime, ZoneOffset::ofTotalSeconds($f->checkValidIntValue($newValue))); } return $this->_with($this->dateTime->with($field, $newValue), $this->offset); } return $field->adjustInto($this, $newValue); }
/** * @dataProvider data_toString */ public function test_parseLowercase(Instant $instant, $text) { $this->assertEquals($instant, Instant::parse(strtolower($text))); }