/** * Converts this date-time to an {@code OffsetTime}. * <p> * This returns an offset time with the same local time and offset. * * @return OffsetTime an OffsetTime representing the time and offset, not null */ public function toOffsetTime() { return OffsetTime::ofLocalTime($this->dateTime->toLocalTime(), $this->offset); }
/** * Adds a single transition rule to the current window. * <p> * This adds a rule such that the offset, expressed as a daylight savings amount, * changes at the specified date-time. * * @param LocalDateTime $transitionDateTime the date-time that the transition occurs as defined by timeDefintion, not null * @param TimeDefinition $timeDefinition the definition of how to convert local to actual time, not null * @param int $savingAmountSecs the amount of saving from the standard offset after the transition in seconds * @return ZoneRulesBuilder $this, for chaining * @throws \LogicException if no window has yet been added * @throws \LogicException if the window already has fixed savings * @throws \LogicException if the window has reached the maximum capacity of 2000 rules */ public function addRuleToWindow(LocalDateTime $transitionDateTime, TimeDefinition $timeDefinition, $savingAmountSecs) { return $this->addRuleToWindow9($transitionDateTime->getYear(), $transitionDateTime->getYear(), $transitionDateTime->getMonth(), $transitionDateTime->getDayOfMonth(), null, $transitionDateTime->toLocalTime(), false, $timeDefinition, $savingAmountSecs); }
private function compareTo0(LocalDateTime $other) { $cmp = $this->date->compareTo0($other->toLocalDate()); if ($cmp == 0) { $cmp = $this->time->compareTo($other->toLocalTime()); } return $cmp; }
public function test_factory_of_LocalDateLocalTime_inGap() { $test = ZonedDateTime::ofDateAndTime($this->TEST_PARIS_GAP_2008_03_30_02_30->toLocalDate(), $this->TEST_PARIS_GAP_2008_03_30_02_30->toLocalTime(), self::ZONE_PARIS()); $this->check($test, 2008, 3, 30, 3, 30, 0, 0, self::OFFSET_0200(), self::ZONE_PARIS()); // one $hour later in summer $offset }
/** * Returns an adjusted copy of this date-time. * <p> * This returns a {@code ZonedDateTime}, based on this one, with the date-time adjusted. * The adjustment takes place using the specified adjuster strategy object. * Read the documentation of the adjuster to understand what adjustment will be made. * <p> * A simple adjuster might simply set the one of the fields, such as the year field. * A more complex adjuster might set the date to the last day of the month. * A selection of common adjustments is provided in * {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}. * These include finding the "last day of the month" and "next Wednesday". * Key date-time classes also implement the {@code TemporalAdjuster} interface, * such as {@link Month} and {@link java.time.MonthDay MonthDay}. * The adjuster is responsible for handling special cases, such as the varying * lengths of month and leap years. * <p> * For example this code returns a date on the last day of July: * <pre> * import static java.time.Month.*; * import static java.time.temporal.TemporalAdjusters.*; * * result = zonedDateTime.with(JULY).with(lastDayOfMonth()); * </pre> * <p> * The classes {@link LocalDate} and {@link LocalTime} implement {@code TemporalAdjuster}, * thus this method can be used to change the date, time or offset: * <pre> * result = zonedDateTime.with(date); * result = zonedDateTime.with(time); * </pre> * <p> * {@link ZoneOffset} also implements {@code TemporalAdjuster} however using it * as an argument typically has no effect. The offset of a {@code ZonedDateTime} is * controlled primarily by the time-zone. As such, changing the offset does not generally * make sense, because there is only one valid offset for the local date-time and zone. * If the zoned date-time is in a daylight savings overlap, then the offset is used * to switch between the two valid offsets. In all other cases, the offset is ignored. * <p> * The result of this method is obtained by invoking the * {@link TemporalAdjuster#adjustInto(Temporal)} method on the * specified adjuster passing {@code this} as the argument. * <p> * This instance is immutable and unaffected by this method call. * * @param TemporalAdjuster $adjuster the adjuster to use, not null * @return ZonedDateTime a {@code ZonedDateTime} based on {@code this} with the adjustment made, not null * @throws DateTimeException if the adjustment cannot be made * @throws ArithmeticException if numeric overflow occurs */ public function adjust(TemporalAdjuster $adjuster) { // optimizations if ($adjuster instanceof LocalDate) { return $this->resolveLocal(LocalDateTime::ofDateAndTime($adjuster, $this->dateTime->toLocalTime())); } else { if ($adjuster instanceof LocalTime) { return $this->resolveLocal(LocalDateTime::ofDateAndTime($this->dateTime->toLocalDate(), $adjuster)); } else { if ($adjuster instanceof LocalDateTime) { return $this->resolveLocal($adjuster); } else { if ($adjuster instanceof OffsetDateTime) { $odt = $adjuster; return self::ofLocal($odt->toLocalDateTime(), $this->zone, $odt->getOffset()); } else { if ($adjuster instanceof Instant) { $instant = $adjuster; return self::create($instant->getEpochSecond(), $instant->getNano(), $this->zone); } else { if ($adjuster instanceof ZoneOffset) { return $this->resolveOffset($adjuster); } } } } } } return $adjuster->adjustInto($this); }