Esempio n. 1
0
 /**
  * Converts the specified local date-time to the local date-time actually
  * seen on a wall clock.
  * <p>
  * This method converts using the type of this enum.
  * The output is defined relative to the 'before' offset of the transition.
  * <p>
  * The UTC type uses the UTC offset.
  * The STANDARD type uses the standard offset.
  * The WALL type returns the input date-time.
  * The result is intended for use with the wall-offset.
  *
  * @param LocalDateTime $dateTime the local date-time, not null
  * @param ZoneOffset $standardOffset the standard offset, not null
  * @param ZoneOffset $wallOffset the wall offset, not null
  * @return LocalDateTime the date-time relative to the wall/before offset, not null
  */
 public function createDateTime(LocalDateTime $dateTime, ZoneOffset $standardOffset, ZoneOffset $wallOffset)
 {
     switch ($this->val) {
         case 0:
             $difference = $wallOffset->getTotalSeconds() - ZoneOffset::UTC()->getTotalSeconds();
             return $dateTime->plusSeconds($difference);
         case 2:
             $difference = $wallOffset->getTotalSeconds() - $standardOffset->getTotalSeconds();
             return $dateTime->plusSeconds($difference);
         default:
             // WALL
             return $dateTime;
     }
 }
 /**
  * @setUp
  */
 public function setUp()
 {
     $this->builder = new DateTimeFormatterBuilder();
     $this->dta = ZonedDateTime::ofDateTime(LocalDateTime::of(2011, 6, 30, 12, 30, 40, 0), ZoneId::of("Europe/Paris"));
     $this->locale = Locale::of("en");
     $this->decimalStyle = DecimalStyle::STANDARD();
 }
Esempio n. 3
0
 public function testMinDateEpochSec()
 {
     $offset = ZoneOffset::ofTotalSeconds(0);
     $seconds = LocalDateTime::MIN()->toEpochSecond($offset);
     $new = LocalDateTime::ofEpochSecond($seconds, 0, $offset);
     $this->assertEquals(LocalDateTime::MIN(), $new);
 }
Esempio n. 4
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);
 }
Esempio n. 5
0
 private function toDateTime($year)
 {
     $this->adjustToFowards($year);
     if ($this->dayOfMonth === -1) {
         $dayOfMonth = $this->month->length(Year::isLeapYear($year));
         $date = LocalDate::ofMonth($year, $this->month, $dayOfMonth);
         if ($this->dayOfWeek !== null) {
             $date = $date->adjust(TemporalAdjusters::previousOrSame($this->dayOfWeek));
         }
     } else {
         $date = LocalDate::ofMonth($year, $this->month, $this->dayOfMonth);
         if ($this->dayOfWeek !== null) {
             $date = $date->adjust(TemporalAdjusters::nextOrSame($this->dayOfWeek));
         }
     }
     $ldt = LocalDateTime::ofDateAndTime($date, $this->time);
     if ($this->endOfDay) {
         $ldt = $ldt->plusDays(1);
     }
     return $ldt;
 }
Esempio n. 6
0
 /**
  * Outputs this date-time as a {@code String}, such as {@code 2007-12-03T10:15:30+01:00}.
  * <p>
  * The output will be one of the following ISO-8601 formats:
  * <ul>
  * <li>{@code uuuu-MM-dd'T'HH:mmXXXXX}</li>
  * <li>{@code uuuu-MM-dd'T'HH:mm:ssXXXXX}</li>
  * <li>{@code uuuu-MM-dd'T'HH:mm:ss.SSSXXXXX}</li>
  * <li>{@code uuuu-MM-dd'T'HH:mm:ss.SSSSSSXXXXX}</li>
  * <li>{@code uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSSXXXXX}</li>
  * </ul>
  * The format used will be the shortest that outputs the full value of
  * the time where the omitted parts are implied to be zero.
  *
  * @return string a string representation of this date-time, not null
  */
 public function __toString()
 {
     return $this->dateTime->__toString() . $this->offset->__toString();
 }
 private static function ZDT()
 {
     return LocalDateTime::of(2008, 6, 30, 11, 30, 10, 500)->atZone(ZoneOffset::ofHours(2));
 }
 public function test_parseBest_firstOption()
 {
     $test = DateTimeFormatter::ofPattern("yyyy-MM-dd HH:mm[XXX]");
     $result = $test->parseBest("2011-06-30 12:30+03:00", TemporalQueries::fromCallable([ZonedDateTime::class, "from"]), TemporalQueries::fromCallable([LocalDateTime::class, "from"]));
     $ldt = LocalDateTime::of(2011, 6, 30, 12, 30);
     $this->assertEquals($result, ZonedDateTime::ofDateTime($ldt, ZoneOffset::ofHours(3)));
 }
Esempio n. 9
0
 /**
  * Combines this date with the time of midnight to create a {@code LocalDateTime}
  * at the start of this date.
  * <p>
  * This returns a {@code LocalDateTime} formed from this date at the time of
  * midnight, 00:00, at the start of this date.
  *
  * @return LocalDateTime the local date-time of midnight at the start of this date, not null
  */
 public function atStartOfDay()
 {
     return LocalDateTime::ofDateAndTime($this, LocalTime::MIDNIGHT());
 }
 private function dt($year, $month, $day, $hour, $min, $sec, $nano)
 {
     return LocalDateTime::of($year, $month, $day, $hour, $min, $sec, $nano);
 }
Esempio n. 11
0
 /**
  * Obtains an ISO local date-time from another date-time object.
  * <p>
  * This is equivalent to {@link LocalDateTime#from(TemporalAccessor)}.
  *
  * @param TemporalAccessor $temporal the date-time object to convert, not null
  * @return LocalDateTime the ISO local date-time, not null
  * @throws DateTimeException if unable to create the date-time
  */
 public function localDateTime(TemporalAccessor $temporal)
 {
     return LocalDateTime::from($temporal);
 }
Esempio n. 12
0
 /**
  * Finds the offset info for a local date-time and transition.
  *
  * @param LocalDateTime $dt the date-time, not null
  * @param ZoneOffsetTransition $trans the transition, not null
  * @return ZoneOffsetTransition|ZoneOffset the offset info, not null
  */
 private function findOffsetInfo(LocalDateTime $dt, ZoneOffsetTransition $trans)
 {
     $localTransition = $trans->getDateTimeBefore();
     if ($trans->isGap()) {
         if ($dt->isBefore($localTransition)) {
             return $trans->getOffsetBefore();
         }
         if ($dt->isBefore($trans->getDateTimeAfter())) {
             return $trans;
         } else {
             return $trans->getOffsetAfter();
         }
     } else {
         if ($dt->isBefore($localTransition) == false) {
             return $trans->getOffsetAfter();
         }
         if ($dt->isBefore($trans->getDateTimeAfter())) {
             return $trans->getOffsetBefore();
         } else {
             return $trans;
         }
     }
 }
 /**
  * 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);
 }
 public function test_createTransition_fixedDate()
 {
     $test = ZoneOffsetTransitionRule::of(Month::MARCH(), 20, null, self::TIME_0100(), false, TimeDefinition::STANDARD(), self::OFFSET_0200(), self::OFFSET_0200(), self::OFFSET_0300());
     $trans = ZoneOffsetTransition::of(LocalDateTime::ofMonth(2000, Month::MARCH(), 20, 1, 0), self::OFFSET_0200(), self::OFFSET_0300());
     $this->assertEquals($test->createTransition(2000), $trans);
 }
 public function withLaterOffsetAtOverlap()
 {
     $trans = $this->getZone()->getRules()->getTransition(LocalDateTime::from($this));
     if ($trans !== null) {
         $offset = $trans->getOffsetAfter();
         if ($offset->equals($this->getOffset()) === false) {
             return new ChronoZonedDateTimeImpl($this->dateTime, $offset, $this->zone);
         }
     }
     return $this;
 }
 /**
  * @dataProvider data_instantNoZone
  * @expectedException \Celest\DateTimeException
  */
 public function test_parse_instantNoZone_LDT(DateTimeFormatter $formatter, $text, Instant $expected)
 {
     $actual = $formatter->parse($text);
     LocalDateTime::from($actual);
 }
Esempio n. 17
0
 function data_durationBetweenLocalDateTime()
 {
     return [[LocalDateTime::of(2013, 3, 24, 0, 44, 31, 565000000), LocalDateTime::of(2013, 3, 24, 0, 44, 30, 65000000), -2, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 565000000), LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), -1, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 565000000), LocalDateTime::of(2013, 3, 24, 0, 44, 32, 65000000), 0, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 565000000), LocalDateTime::of(2013, 3, 24, 0, 44, 33, 65000000), 1, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 565000000), LocalDateTime::of(2013, 3, 24, 0, 44, 34, 65000000), 2, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2013, 3, 24, 0, 44, 30, 565000000), -1, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2013, 3, 24, 0, 44, 31, 565000000), 0, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2013, 3, 24, 0, 44, 32, 565000000), 1, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2013, 3, 24, 0, 44, 33, 565000000), 2, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2013, 3, 24, 0, 44, 34, 565000000), 3, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2013, 3, 24, 0, 44, 30, 65000000), -1, 0], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), 0, 0], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2013, 3, 24, 0, 44, 32, 65000000), 1, 0], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2013, 3, 24, 0, 44, 33, 65000000), 2, 0], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2013, 3, 24, 0, 44, 34, 65000000), 3, 0], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2813, 3, 24, 0, 44, 30, 565000000), 2 * self::CYCLE_SECS - 1, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2813, 3, 24, 0, 44, 31, 565000000), 2 * self::CYCLE_SECS + 0, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2813, 3, 24, 0, 44, 32, 565000000), 2 * self::CYCLE_SECS + 1, 500000000]];
 }
Esempio n. 18
0
 function data_quartersBetween()
 {
     return [[LocalDate::of(2000, 1, 1), LocalDate::of(2000, 1, 1), 0], [LocalDate::of(2000, 1, 1), LocalDate::of(2000, 1, 2), 0], [LocalDate::of(2000, 1, 1), LocalDate::of(2000, 2, 1), 0], [LocalDate::of(2000, 1, 1), LocalDate::of(2000, 3, 1), 0], [LocalDate::of(2000, 1, 1), LocalDate::of(2000, 3, 31), 0], [LocalDate::of(2000, 1, 1), LocalDate::of(2000, 4, 1), 1], [LocalDate::of(2000, 1, 1), LocalDate::of(2000, 4, 2), 1], [LocalDate::of(2000, 1, 1), LocalDate::of(2000, 6, 30), 1], [LocalDate::of(2000, 1, 1), LocalDate::of(2000, 7, 1), 2], [LocalDate::of(2000, 1, 1), LocalDate::of(2000, 10, 1), 3], [LocalDate::of(2000, 1, 1), LocalDate::of(2000, 12, 31), 3], [LocalDate::of(2000, 1, 1), LocalDate::of(2001, 1, 1), 4], [LocalDate::of(2000, 1, 1), LocalDate::of(2002, 1, 1), 8], [LocalDate::of(2000, 1, 1), LocalDate::of(1999, 12, 31), 0], [LocalDate::of(2000, 1, 1), LocalDate::of(1999, 10, 2), 0], [LocalDate::of(2000, 1, 1), LocalDate::of(1999, 10, 1), -1], [LocalDate::of(2000, 1, 1), LocalDate::of(1999, 7, 2), -1], [LocalDate::of(2000, 1, 1), LocalDate::of(1999, 7, 1), -2], [LocalDate::of(2000, 1, 1), LocalDate::of(1999, 4, 2), -2], [LocalDate::of(2000, 1, 1), LocalDate::of(1999, 4, 1), -3], [LocalDate::of(2000, 1, 1), LocalDate::of(1999, 1, 2), -3], [LocalDate::of(2000, 1, 1), LocalDate::of(1999, 1, 1), -4], [LocalDate::of(2000, 1, 1), LocalDate::of(1998, 12, 31), -4], [LocalDate::of(2000, 1, 1), LocalDate::of(1998, 10, 2), -4], [LocalDate::of(2000, 1, 1), LocalDate::of(1998, 10, 1), -5], [LocalDate::of(2000, 1, 1), LocalDateTime::of(2001, 4, 5, 0, 0), 5]];
 }
Esempio n. 19
0
 public function test_now_Clock()
 {
     $instant = LocalDateTime::of(2010, 12, 31, 0, 0)->toInstant(ZoneOffset::UTC());
     $clock = Clock::fixed($instant, ZoneOffset::UTC());
     $test = YearMonth::nowOf($clock);
     $this->assertEquals($test->getYear(), 2010);
     $this->assertEquals($test->getMonth(), Month::DECEMBER());
 }
Esempio n. 20
0
 public function data_formatStyle()
 {
     return [[ZonedDateTime::ofDateTime(LocalDateTime::of(2001, 10, 2, 1, 2, 3), self::ZONEID_PARIS()), FormatStyle::FULL(), "Tuesday, October 2, 2001 1:02:03 AM CEST Europe/Paris"], [ZonedDateTime::ofDateTime(LocalDateTime::of(2001, 10, 2, 1, 2, 3), self::ZONEID_PARIS()), FormatStyle::LONG(), "October 2, 2001 1:02:03 AM CEST Europe/Paris"], [ZonedDateTime::ofDateTime(LocalDateTime::of(2001, 10, 2, 1, 2, 3), self::ZONEID_PARIS()), FormatStyle::MEDIUM(), "Oct 2, 2001, 1:02:03 AM Europe/Paris"], [ZonedDateTime::ofDateTime(LocalDateTime::of(2001, 10, 2, 1, 2, 3), self::ZONEID_PARIS()), FormatStyle::SHORT(), "10/2/01, 1:02 AM Europe/Paris"], [ZonedDateTime::ofDateTime(LocalDateTime::of(2001, 10, 2, 1, 2, 3), self::OFFSET_PTWO()), FormatStyle::FULL(), "Tuesday, October 2, 2001 at 1:02:03 AM +02:00 +02:00"], [ZonedDateTime::ofDateTime(LocalDateTime::of(2001, 10, 2, 1, 2, 3), self::OFFSET_PTWO()), FormatStyle::LONG(), "October 2, 2001 at 1:02:03 AM +02:00 +02:00"], [ZonedDateTime::ofDateTime(LocalDateTime::of(2001, 10, 2, 1, 2, 3), self::OFFSET_PTWO()), FormatStyle::MEDIUM(), "Oct 2, 2001, 1:02:03 AM +02:00"], [ZonedDateTime::ofDateTime(LocalDateTime::of(2001, 10, 2, 1, 2, 3), self::OFFSET_PTWO()), FormatStyle::SHORT(), "10/2/01, 1:02 AM +02:00"]];
 }
 private static function dateTimeZoned($year, $month, $dayOfMonth, $hour, $minute, $second, $nanoOfSecond, ZoneOffset $offset, ZoneId $zoneId)
 {
     return ZonedDateTime::ofStrict(LocalDateTime::of($year, $month, $dayOfMonth, $hour, $minute, $second, $nanoOfSecond), $offset, $zoneId);
 }
Esempio n. 22
0
 function data_atStartOfDayZoneId()
 {
     return [[LocalDate::of(2008, 6, 30), self::ZONE_PARIS(), ZonedDateTime::ofDateTime(LocalDateTime::of(2008, 6, 30, 0, 0), self::ZONE_PARIS())], [LocalDate::of(2008, 6, 30), self::OFFSET_PONE(), ZonedDateTime::ofDateTime(LocalDateTime::of(2008, 6, 30, 0, 0), self::OFFSET_PONE())], [LocalDate::of(2007, 4, 1), self::ZONE_GAZA(), ZonedDateTime::ofDateTime(LocalDateTime::of(2007, 4, 1, 1, 0), self::ZONE_GAZA())]];
 }
Esempio n. 23
0
 /**
  * Combines this time with a date to create a {@code LocalDateTime}.
  * <p>
  * This returns a {@code LocalDateTime} formed from this time at the specified date.
  * All possible combinations of date and time are valid.
  *
  * @param LocalDate $date the date to combine with, not null
  * @return LocalDateTime LocalTime the local date-time formed from this time and the specified date, not null
  */
 public function atDate(LocalDate $date)
 {
     return LocalDateTime::ofDateAndTime($date, $this);
 }
Esempio n. 24
0
 /**
  * Checks if the window is empty.
  *
  * @return bool true if the window is only a standard offset
  */
 function isSingleWindowStandardOffset()
 {
     return $this->windowEnd->equals(LocalDateTime::MAX()) && $this->timeDefinition == TimeDefinition::WALL() && $this->fixedSavingAmountSecs === null && empty($this->lastRuleList) && empty($this->ruleList);
 }
Esempio n. 25
0
 private function createLDT($year, $month, $day)
 {
     return LocalDateTime::of($year, $month, $day, 0, 0);
 }
Esempio n. 26
0
 function data_fieldAndAccessor()
 {
     return [[CF::YEAR(), LocalDate::of(2000, 2, 29), true, 2000], [CF::YEAR(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 2000], [CF::MONTH_OF_YEAR(), LocalDate::of(2000, 2, 29), true, 2], [CF::MONTH_OF_YEAR(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 2], [CF::DAY_OF_MONTH(), LocalDate::of(2000, 2, 29), true, 29], [CF::DAY_OF_MONTH(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 29], [CF::DAY_OF_YEAR(), LocalDate::of(2000, 2, 29), true, 60], [CF::DAY_OF_YEAR(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 60], [CF::HOUR_OF_DAY(), LocalTime::of(5, 4, 3, 200), true, 5], [CF::HOUR_OF_DAY(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 5], [CF::MINUTE_OF_DAY(), LocalTime::of(5, 4, 3, 200), true, 5 * 60 + 4], [CF::MINUTE_OF_DAY(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 5 * 60 + 4], [CF::MINUTE_OF_HOUR(), LocalTime::of(5, 4, 3, 200), true, 4], [CF::MINUTE_OF_HOUR(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 4], [CF::SECOND_OF_DAY(), LocalTime::of(5, 4, 3, 200), true, 5 * 3600 + 4 * 60 + 3], [CF::SECOND_OF_DAY(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 5 * 3600 + 4 * 60 + 3], [CF::SECOND_OF_MINUTE(), LocalTime::of(5, 4, 3, 200), true, 3], [CF::SECOND_OF_MINUTE(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 3], [CF::NANO_OF_SECOND(), LocalTime::of(5, 4, 3, 200), true, 200], [CF::NANO_OF_SECOND(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 200], [CF::YEAR(), LocalTime::of(5, 4, 3, 200), false, -1], [CF::MONTH_OF_YEAR(), LocalTime::of(5, 4, 3, 200), false, -1], [CF::DAY_OF_MONTH(), LocalTime::of(5, 4, 3, 200), false, -1], [CF::DAY_OF_YEAR(), LocalTime::of(5, 4, 3, 200), false, -1], [CF::HOUR_OF_DAY(), LocalDate::of(2000, 2, 29), false, -1], [CF::MINUTE_OF_DAY(), LocalDate::of(2000, 2, 29), false, -1], [CF::MINUTE_OF_HOUR(), LocalDate::of(2000, 2, 29), false, -1], [CF::SECOND_OF_DAY(), LocalDate::of(2000, 2, 29), false, -1], [CF::SECOND_OF_MINUTE(), LocalDate::of(2000, 2, 29), false, -1], [CF::NANO_OF_SECOND(), LocalDate::of(2000, 2, 29), false, -1]];
 }
Esempio n. 27
0
 /**
  * Completes the build converting the builder to a set of time-zone rules.
  * <p>
  * Calling this method alters the state of the builder.
  * Further rules should not be added to this builder once this method is called.
  *
  * @param string $zoneId the time-zone ID, not null
  * @param array $deduplicateMap a map for deduplicating the values, not null
  * @return ZoneRules the zone rules, not null
  * @throws \LogicException if no windows have been added
  * @throws \LogicException if there is only one rule defined as being forever for any given window
  */
 public function _toRules($zoneId, &$deduplicateMap)
 {
     $this->deduplicateMap = $deduplicateMap;
     if (empty($this->windowList)) {
         throw new \LogicException("No windows have been added to the builder");
     }
     /** @var ZoneOffsetTransition[] $standardTransitionList */
     $standardTransitionList = [];
     /** @var ZoneOffsetTransition[] */
     $transitionList = [];
     /** @var ZoneOffsetTransitionRule[] */
     $lastTransitionRuleList = [];
     // initialize the standard offset calculation
     $firstWindow = $this->windowList[0];
     $loopStandardOffset = $firstWindow->standardOffset;
     $loopSavings = 0;
     if ($firstWindow->fixedSavingAmountSecs !== null) {
         $loopSavings = $firstWindow->fixedSavingAmountSecs;
     }
     /** @var ZoneOffset $firstWallOffset */
     $firstWallOffset = $this->deduplicate(ZoneOffset::ofTotalSeconds($loopStandardOffset->getTotalSeconds() + $loopSavings));
     /** @var LocalDateTime $loopWindowStart */
     $loopWindowStart = $this->deduplicate(LocalDateTime::of(Year::MIN_VALUE, 1, 1, 0, 0));
     $loopWindowOffset = $firstWallOffset;
     // build the windows and rules to interesting data
     foreach ($this->windowList as $window) {
         // tidy the state
         $window->tidy($loopWindowStart->getYear());
         // calculate effective savings at the start of the window
         $effectiveSavings = $window->fixedSavingAmountSecs;
         if ($effectiveSavings === null) {
             // apply rules from this window together with the standard offset and
             // savings from the last window to find the savings amount applicable
             // at start of this window
             $effectiveSavings = 0;
             foreach ($window->ruleList as $rule) {
                 $trans = $rule->toTransition($loopStandardOffset, $loopSavings);
                 if ($trans->toEpochSecond() > $loopWindowStart->toEpochSecond($loopWindowOffset)) {
                     // previous savings amount found, which could be the savings amount at
                     // the instant that the window starts (hence isAfter)
                     break;
                 }
                 $effectiveSavings = $rule->savingAmountSecs;
             }
         }
         // check if standard offset changed, and update it
         if ($loopStandardOffset->equals($window->standardOffset) === false) {
             $standardTransitionList[] = $this->deduplicate(ZoneOffsetTransition::of(LocalDateTime::ofEpochSecond($loopWindowStart->toEpochSecond($loopWindowOffset), 0, $loopStandardOffset), $loopStandardOffset, $window->standardOffset));
             $loopStandardOffset = $this->deduplicate($window->standardOffset);
         }
         // check if the start of the window represents a transition
         $effectiveWallOffset = $this->deduplicate(ZoneOffset::ofTotalSeconds($loopStandardOffset->getTotalSeconds() + $effectiveSavings));
         if ($loopWindowOffset->equals($effectiveWallOffset) === false) {
             $trans = $this->deduplicate(ZoneOffsetTransition::of($loopWindowStart, $loopWindowOffset, $effectiveWallOffset));
             $transitionList[] = $trans;
         }
         $loopSavings = $effectiveSavings;
         // apply rules within the window
         foreach ($window->ruleList as $rule) {
             /** @var ZoneOffsetTransition $trans */
             $trans = $this->deduplicate($rule->toTransition($loopStandardOffset, $loopSavings));
             if ($trans !== null && $trans->toEpochSecond() < $loopWindowStart->toEpochSecond($loopWindowOffset) === false && $trans->toEpochSecond() < $window->createDateTimeEpochSecond($loopSavings) && $trans->getOffsetBefore()->equals($trans->getOffsetAfter()) === false) {
                 $transitionList[] = $trans;
                 $loopSavings = $rule->savingAmountSecs;
             }
         }
         // calculate last rules
         foreach ($window->lastRuleList as $lastRule) {
             $transitionRule = $this->deduplicate($lastRule->toTransitionRule($loopStandardOffset, $loopSavings));
             $lastTransitionRuleList[] = $transitionRule;
             $loopSavings = $lastRule->savingAmountSecs;
         }
         // finally we can calculate the true end of the window, passing it to the next window
         $loopWindowOffset = $this->deduplicate($window->createWallOffset($loopSavings));
         $loopWindowStart = $this->deduplicate(LocalDateTime::ofEpochSecond($window->createDateTimeEpochSecond($loopSavings), 0, $loopWindowOffset));
     }
     return ZoneRules::of($firstWindow->standardOffset, $firstWallOffset, $standardTransitionList, $transitionList, $lastTransitionRuleList);
 }
 public function test_with_adjustment_LocalDateTime()
 {
     $test = self::TEST_2008_6_30_11_30_59_000000500()->adjust(LocalDateTime::ofDateAndTime(LocalDate::of(2012, 9, 3), LocalTime::of(19, 15)));
     $this->assertEquals($test, OffsetDateTime::ofDateAndTime(LocalDate::of(2012, 9, 3), LocalTime::of(19, 15), self::OFFSET_PONE()));
 }
Esempio n. 29
0
 public function test_factory_CalendricalObject()
 {
     $this->assertEquals(ZoneOffset::from(ZonedDateTime::ofDateTime(LocalDateTime::ofDateAndTime(LocalDate::of(2007, 7, 15), LocalTime::of(17, 30)), ZoneOffset::ofHours(2))), ZoneOffset::ofHours(2));
 }
 public function test_appendTextMapIncomplete()
 {
     $map = [1, "JNY"];
     $this->builder->appendText3(ChronoField::MONTH_OF_YEAR(), $map);
     $f = $this->builder->toFormatter();
     $dt = LocalDateTime::of(2010, 2, 1, 0, 0);
     $this->assertEquals($f->format($dt), "2");
 }