Exemplo n.º 1
0
 /**
  * Converts this to a transition.
  *
  * @param ZoneOffset $standardOffset the active standard offset, not null
  * @param int $savingsBeforeSecs the active savings in seconds
  * @return ZoneOffsetTransition the transition, not null
  */
 function toTransition(ZoneOffset $standardOffset, $savingsBeforeSecs)
 {
     // copy of code in ZoneOffsetTransitionRule to avoid infinite loop
     $date = $this->toLocalDate();
     $date = ZoneRulesBuilder::deduplicate($date);
     $ldt = ZoneRulesBuilder::deduplicate(LocalDateTime::ofDateAndTime($date, $this->time));
     /** @var ZoneOffset $wallOffset */
     $wallOffset = ZoneRulesBuilder::deduplicate(ZoneOffset::ofTotalSeconds($standardOffset->getTotalSeconds() + $savingsBeforeSecs));
     $dt = ZoneRulesBuilder::deduplicate($this->timeDefinition->createDateTime($ldt, $standardOffset, $wallOffset));
     $offsetAfter = ZoneRulesBuilder::deduplicate(ZoneOffset::ofTotalSeconds($standardOffset->getTotalSeconds() + $this->savingAmountSecs));
     return new ZoneOffsetTransition($dt, $wallOffset, $offsetAfter);
 }
Exemplo n.º 2
0
 /**
  * Creates the offset date-time for the local date-time at the end of the window.
  *
  * @param int $savingsSecs the amount of savings in use in seconds
  * @return int the created date-time epoch second in the wall offset, not null
  */
 function createDateTimeEpochSecond($savingsSecs)
 {
     $wallOffset = $this->createWallOffset($savingsSecs);
     $ldt = $this->timeDefinition->createDateTime($this->windowEnd, $this->standardOffset, $wallOffset);
     return $ldt->toEpochSecond($wallOffset);
 }
 /**
  * Creates a transition instance for the specified year.
  * <p>
  * Calculations are performed using the ISO-8601 chronology.
  *
  * @param int $year the year to create a transition for, not null
  * @return ZoneOffsetTransition the transition instance, not null
  */
 public function createTransition($year)
 {
     if ($this->dom < 0) {
         $date = LocalDate::ofMonth($year, $this->month, $this->month->length(IsoChronology::INSTANCE()->isLeapYear($year)) + 1 + $this->dom);
         if ($this->dow !== null) {
             $date = $date->adjust(TemporalAdjusters::previousOrSame($this->dow));
         }
     } else {
         $date = LocalDate::ofMonth($year, $this->month, $this->dom);
         if ($this->dow !== null) {
             $date = $date->adjust(TemporalAdjusters::nextOrSame($this->dow));
         }
     }
     if ($this->timeEndOfDay) {
         $date = $date->plusDays(1);
     }
     $localDT = LocalDateTime::ofDateAndTime($date, $this->time);
     $transition = $this->timeDefinition->createDateTime($localDT, $this->standardOffset, $this->offsetBefore);
     return ZoneOffsetTransition::of($transition, $this->offsetBefore, $this->offsetAfter);
 }