/** * Adds a window that applies until the end of time to the builder that can be * used to filter a set of rules. * <p> * This method defines and adds a window to the zone where the standard offset is specified. * The window limits the effect of subsequent additions of transition rules * or fixed savings. If neither rules or fixed savings are added to the window * then the window will default to no savings. * <p> * This must be added after all other windows. * No more windows can be added after this one. * * @param ZoneOffset $standardOffset the standard offset, not null * @return ZoneRulesBuilder $this, for chaining * @throws \LogicException if a forever window has already been added */ public function addWindowForever(ZoneOffset $standardOffset) { return $this->addWindow($standardOffset, LocalDateTime::MAX(), TimeDefinition::WALL()); }
public function test_of() { //used for standard offset $stdOffset1 = ZoneOffset::UTC(); $stdOffset2 = ZoneOffset::ofHours(1); $time_of_stdOffsetTransition1 = LocalDateTime::of(2013, 1, 5, 1, 0); $stdOffsetTransition1 = ZoneOffsetTransition::of($time_of_stdOffsetTransition1, $stdOffset1, $stdOffset2); $stdOffsetTransition_list = []; $stdOffsetTransition_list[] = $stdOffsetTransition1; //used for wall offset $wallOffset1 = ZoneOffset::ofHours(2); $wallOffset2 = ZoneOffset::ofHours(4); $wallOffset3 = ZoneOffset::ofHours(7); $time_of_wallOffsetTransition1 = LocalDateTime::of(2013, 2, 5, 1, 0); $time_of_wallOffsetTransition2 = LocalDateTime::of(2013, 3, 5, 1, 0); $time_of_wallOffsetTransition3 = LocalDateTime::of(2013, 10, 5, 1, 0); $wallOffsetTransition1 = ZoneOffsetTransition::of($time_of_wallOffsetTransition1, $wallOffset1, $wallOffset2); $wallOffsetTransition2 = ZoneOffsetTransition::of($time_of_wallOffsetTransition2, $wallOffset2, $wallOffset3); $wallOffsetTransition3 = ZoneOffsetTransition::of($time_of_wallOffsetTransition3, $wallOffset3, $wallOffset1); $wallOffsetTransition_list = []; $wallOffsetTransition_list[] = $wallOffsetTransition1; $wallOffsetTransition_list[] = $wallOffsetTransition2; $wallOffsetTransition_list[] = $wallOffsetTransition3; //used for ZoneOffsetTransitionRule $ruleOffset = ZoneOffset::ofHours(3); $timeDefinition = TimeDefinition::WALL(); $rule1 = ZoneOffsetTransitionRule::of(Month::FEBRUARY(), 2, DayOfWeek::MONDAY(), LocalTime::of(1, 0), false, $timeDefinition, ZoneOffset::UTC(), ZoneOffset::UTC(), $ruleOffset); $rule_list = []; $rule_list[] = $rule1; //Begin verification $zoneRule = ZoneRules::of($stdOffset1, $wallOffset1, $stdOffsetTransition_list, $wallOffsetTransition_list, $rule_list); $before_time_of_stdOffsetTransition1 = OffsetDateTime::ofDateTime($time_of_stdOffsetTransition1, $stdOffset1)->minusSeconds(1); $after_time_of_stdOffsetTransition1 = OffsetDateTime::ofDateTime($time_of_stdOffsetTransition1, $stdOffset1)->plusSeconds(1); $this->assertEquals($zoneRule->getStandardOffset($before_time_of_stdOffsetTransition1->toInstant()), $stdOffset1); $this->assertEquals($zoneRule->getStandardOffset($after_time_of_stdOffsetTransition1->toInstant()), $stdOffset2); $before_time_of_wallOffsetTransition1 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition1, $wallOffset1)->minusSeconds(1); $after_time_of_wallOffsetTransition1 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition1, $wallOffset1)->plusSeconds(1); $this->assertEquals($zoneRule->nextTransition($before_time_of_wallOffsetTransition1->toInstant()), $wallOffsetTransition1); $this->assertEquals($zoneRule->nextTransition($after_time_of_wallOffsetTransition1->toInstant()), $wallOffsetTransition2); $before_time_of_wallOffsetTransition2 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition2, $wallOffset2)->minusSeconds(1); $after_time_of_wallOffsetTransition2 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition2, $wallOffset2)->plusSeconds(1); $this->assertEquals($zoneRule->nextTransition($before_time_of_wallOffsetTransition2->toInstant()), $wallOffsetTransition2); $this->assertEquals($zoneRule->nextTransition($after_time_of_wallOffsetTransition2->toInstant()), $wallOffsetTransition3); $before_time_of_wallOffsetTransition3 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition3, $wallOffset3)->minusSeconds(1); $after_time_of_wallOffsetTransition3 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition3, $wallOffset3)->plusSeconds(1); $this->assertEquals($zoneRule->nextTransition($before_time_of_wallOffsetTransition3->toInstant()), $wallOffsetTransition3); $this->assertEquals($zoneRule->nextTransition($after_time_of_wallOffsetTransition3->toInstant()), $rule1->createTransition(2014)); }
public function __construct() { $this->month = Month::JANUARY(); $this->time = LocalTime::MIDNIGHT(); $this->timeDefinition = TimeDefinition::WALL(); }
/** * 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); }
public function test_toString_floatingWeekBackwards_secondLast() { $test = ZoneOffsetTransitionRule::of(Month::MARCH(), -2, DayOfWeek::SUNDAY(), self::TIME_0100(), false, TimeDefinition::WALL(), self::OFFSET_0200(), self::OFFSET_0200(), self::OFFSET_0300()); $this->assertEquals($test->__toString(), "TransitionRule[Gap +02:00 to +03:00, SUNDAY on or before last day minus 1 of MARCH at 01:00 WALL, standard offset +02:00]"); }
private function parseTimeDefinition($c) { switch ($c) { case 's': case 'S': // standard time return TimeDefinition::STANDARD(); case 'u': case 'U': case 'g': case 'G': case 'z': case 'Z': // UTC return TimeDefinition::UTC(); case 'w': case 'W': default: // wall time return TimeDefinition::WALL(); } }