/** * 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 year the year of the transition, from MIN_VALUE to MAX_VALUE * @param month the month of the transition, not null * @param dayOfMonthIndicator the day-of-month of the transition, adjusted by dayOfWeek, * from 1 to 31 adjusted later, or -1 to -28 adjusted earlier from the last day of the month * @param time the time that the transition occurs as defined by timeDefintion, not null * @param timeEndOfDay whether midnight is at the end of day * @param timeDefinition the definition of how to convert local to actual time, not null * @param savingAmountSecs the amount of saving from the standard offset after the transition in seconds * @return this, for chaining * @throws DateTimeException if a date-time field is out of range * @throws IllegalStateException if no window has yet been added * @throws IllegalStateException if the window already has fixed savings * @throws IllegalStateException if the window has reached the maximum capacity of 2000 rules */ public ZoneRulesBuilder addRuleToWindow( int year, Month month, int dayOfMonthIndicator, LocalTime time, boolean timeEndOfDay, TimeDefinition timeDefinition, int savingAmountSecs) { return addRuleToWindow(year, year, month, dayOfMonthIndicator, null, time, timeEndOfDay, timeDefinition, savingAmountSecs); }
/** * 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 standardOffset the standard offset, not null * @return this, for chaining * @throws IllegalStateException if a forever window has already been added */ public ZoneRulesBuilder addWindowForever(ZoneOffset standardOffset) { return addWindow(standardOffset, LocalDateTime.MAX, TimeDefinition.WALL); }
/** * 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 zoneId the time-zone ID, not null * @return the zone rules, not null * @throws IllegalStateException if no windows have been added * @throws IllegalStateException if there is only one rule defined as being forever for any given window */ public ZoneRules toRules(String zoneId) { return toRules(zoneId, new HashMap<Object, Object>()); }
ZoneRulesBuilder addToBuilder(ZoneRulesBuilder bld, Map<String, List<TZDBRule>> rules) { if (year != null) { bld.addWindow(standardOffset, toDateTime(year.getValue()), timeDefinition); } else { bld.addWindowForever(standardOffset); } if (fixedSavingsSecs != null) { bld.setFixedSavingsToWindow(fixedSavingsSecs); } else { List<TZDBRule> tzdbRules = rules.get(savingsRule); if (tzdbRules == null) { throw new IllegalArgumentException("Rule not found: " + savingsRule); } for (TZDBRule tzdbRule : tzdbRules) { tzdbRule.addToBuilder(bld); } } return bld; }
zoneId = deduplicate(zoneId); List<TZDBZone> tzdbZones = zones.get(zoneId); ZoneRulesBuilder bld = new ZoneRulesBuilder(); for (TZDBZone tzdbZone : tzdbZones) { bld = tzdbZone.addToBuilder(bld, rules); ZoneRules buildRules = bld.toRules(zoneId, deduplicateMap); builtZones.put(zoneId, deduplicate(buildRules));
/** * Converts this to a transition. * * @param standardOffset the active standard offset, not null * @param savingsBeforeSecs the active savings in seconds * @return the transition, not null */ ZoneOffsetTransition toTransition(ZoneOffset standardOffset, int savingsBeforeSecs) { // copy of code in ZoneOffsetTransitionRule to avoid infinite loop LocalDate date = toLocalDate(); date = deduplicate(date); LocalDateTime ldt = deduplicate(LocalDateTime.of(date.plusDays(adjustDays), time)); ZoneOffset wallOffset = deduplicate(ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingsBeforeSecs)); LocalDateTime dt = deduplicate(timeDefinition.createDateTime(ldt, standardOffset, wallOffset)); ZoneOffset offsetAfter = deduplicate(ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingAmountSecs)); return new ZoneOffsetTransition(dt, wallOffset, offsetAfter); }
ZoneRulesBuilder addToBuilder(ZoneRulesBuilder bld, Map<String, List<TZDBRule>> rules) { if (year != null) { bld.addWindow(standardOffset, toDateTime(year.getValue()), timeDefinition); } else { bld.addWindowForever(standardOffset); } if (fixedSavingsSecs != null) { bld.setFixedSavingsToWindow(fixedSavingsSecs); } else { List<TZDBRule> tzdbRules = rules.get(savingsRule); if (tzdbRules == null) { throw new IllegalArgumentException("Rule not found: " + savingsRule); } for (TZDBRule tzdbRule : tzdbRules) { tzdbRule.addToBuilder(bld); } } return bld; }
zoneId = deduplicate(zoneId); List<TZDBZone> tzdbZones = zones.get(zoneId); ZoneRulesBuilder bld = new ZoneRulesBuilder(); for (TZDBZone tzdbZone : tzdbZones) { bld = tzdbZone.addToBuilder(bld, rules); ZoneRules buildRules = bld.toRules(zoneId, deduplicateMap); builtZones.put(zoneId, deduplicate(buildRules));
/** * Converts this to a transition. * * @param standardOffset the active standard offset, not null * @param savingsBeforeSecs the active savings in seconds * @return the transition, not null */ ZoneOffsetTransition toTransition(ZoneOffset standardOffset, int savingsBeforeSecs) { // copy of code in ZoneOffsetTransitionRule to avoid infinite loop LocalDate date = toLocalDate(); date = deduplicate(date); LocalDateTime ldt = deduplicate(LocalDateTime.of(date.plusDays(adjustDays), time)); ZoneOffset wallOffset = deduplicate(ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingsBeforeSecs)); LocalDateTime dt = deduplicate(timeDefinition.createDateTime(ldt, standardOffset, wallOffset)); ZoneOffset offsetAfter = deduplicate(ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingAmountSecs)); return new ZoneOffsetTransition(dt, wallOffset, offsetAfter); }
/** * 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 year the year of the transition, from MIN_VALUE to MAX_VALUE * @param month the month of the transition, not null * @param dayOfMonthIndicator the day-of-month of the transition, adjusted by dayOfWeek, * from 1 to 31 adjusted later, or -1 to -28 adjusted earlier from the last day of the month * @param time the time that the transition occurs as defined by timeDefintion, not null * @param timeEndOfDay whether midnight is at the end of day * @param timeDefinition the definition of how to convert local to actual time, not null * @param savingAmountSecs the amount of saving from the standard offset after the transition in seconds * @return this, for chaining * @throws DateTimeException if a date-time field is out of range * @throws IllegalStateException if no window has yet been added * @throws IllegalStateException if the window already has fixed savings * @throws IllegalStateException if the window has reached the maximum capacity of 2000 rules */ public ZoneRulesBuilder addRuleToWindow( int year, Month month, int dayOfMonthIndicator, LocalTime time, boolean timeEndOfDay, TimeDefinition timeDefinition, int savingAmountSecs) { return addRuleToWindow(year, year, month, dayOfMonthIndicator, null, time, timeEndOfDay, timeDefinition, savingAmountSecs); }
final ZoneOffset firstWallOffset = deduplicate(ZoneOffset.ofTotalSeconds(loopStandardOffset.getTotalSeconds() + loopSavings)); LocalDateTime loopWindowStart = deduplicate(LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0)); ZoneOffset loopWindowOffset = firstWallOffset; standardTransitionList.add(deduplicate( new ZoneOffsetTransition( LocalDateTime.ofEpochSecond(loopWindowStart.toEpochSecond(loopWindowOffset), 0, loopStandardOffset), loopStandardOffset, window.standardOffset))); loopStandardOffset = deduplicate(window.standardOffset); ZoneOffset effectiveWallOffset = deduplicate(ZoneOffset.ofTotalSeconds(loopStandardOffset.getTotalSeconds() + effectiveSavings)); if (loopWindowOffset.equals(effectiveWallOffset) == false) { ZoneOffsetTransition trans = deduplicate( new ZoneOffsetTransition(loopWindowStart, loopWindowOffset, effectiveWallOffset)); transitionList.add(trans); ZoneOffsetTransition trans = deduplicate(rule.toTransition(loopStandardOffset, loopSavings)); if (trans.toEpochSecond() < loopWindowStart.toEpochSecond(loopWindowOffset) == false && trans.toEpochSecond() < window.createDateTimeEpochSecond(loopSavings) && ZoneOffsetTransitionRule transitionRule = deduplicate(lastRule.toTransitionRule(loopStandardOffset, loopSavings)); lastTransitionRuleList.add(transitionRule); loopSavings = lastRule.savingAmountSecs; loopWindowOffset = deduplicate(window.createWallOffset(loopSavings)); loopWindowStart = deduplicate(LocalDateTime.ofEpochSecond( window.createDateTimeEpochSecond(loopSavings), 0, loopWindowOffset));
/** * 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 zoneId the time-zone ID, not null * @return the zone rules, not null * @throws IllegalStateException if no windows have been added * @throws IllegalStateException if there is only one rule defined as being forever for any given window */ public ZoneRules toRules(String zoneId) { return toRules(zoneId, new HashMap<Object, Object>()); }
/** * 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 standardOffset the standard offset, not null * @return this, for chaining * @throws IllegalStateException if a forever window has already been added */ public ZoneRulesBuilder addWindowForever(ZoneOffset standardOffset) { return addWindow(standardOffset, LocalDateTime.MAX, TimeDefinition.WALL); }
void addToBuilder(ZoneRulesBuilder bld) { adjustToFowards(2004); // irrelevant, treat as leap year bld.addRuleToWindow(startYear, endYear, month, dayOfMonth, dayOfWeek, time, adjustDays, timeDefinition, savingsAmount); } }
final ZoneOffset firstWallOffset = deduplicate(ZoneOffset.ofTotalSeconds(loopStandardOffset.getTotalSeconds() + loopSavings)); LocalDateTime loopWindowStart = deduplicate(LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0)); ZoneOffset loopWindowOffset = firstWallOffset; standardTransitionList.add(deduplicate( new ZoneOffsetTransition( LocalDateTime.ofEpochSecond(loopWindowStart.toEpochSecond(loopWindowOffset), 0, loopStandardOffset), loopStandardOffset, window.standardOffset))); loopStandardOffset = deduplicate(window.standardOffset); ZoneOffset effectiveWallOffset = deduplicate(ZoneOffset.ofTotalSeconds(loopStandardOffset.getTotalSeconds() + effectiveSavings)); if (loopWindowOffset.equals(effectiveWallOffset) == false) { ZoneOffsetTransition trans = deduplicate( new ZoneOffsetTransition(loopWindowStart, loopWindowOffset, effectiveWallOffset)); transitionList.add(trans); ZoneOffsetTransition trans = deduplicate(rule.toTransition(loopStandardOffset, loopSavings)); if (trans.toEpochSecond() < loopWindowStart.toEpochSecond(loopWindowOffset) == false && trans.toEpochSecond() < window.createDateTimeEpochSecond(loopSavings) && ZoneOffsetTransitionRule transitionRule = deduplicate(lastRule.toTransitionRule(loopStandardOffset, loopSavings)); lastTransitionRuleList.add(transitionRule); loopSavings = lastRule.savingAmountSecs; loopWindowOffset = deduplicate(window.createWallOffset(loopSavings)); loopWindowStart = deduplicate(LocalDateTime.ofEpochSecond( window.createDateTimeEpochSecond(loopSavings), 0, loopWindowOffset));
void addToBuilder(ZoneRulesBuilder bld) { adjustToFowards(2004); // irrelevant, treat as leap year bld.addRuleToWindow(startYear, endYear, month, dayOfMonth, dayOfWeek, time, adjustDays, timeDefinition, savingsAmount); } }
/** * 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 transitionDateTime the date-time that the transition occurs as defined by timeDefintion, not null * @param timeDefinition the definition of how to convert local to actual time, not null * @param savingAmountSecs the amount of saving from the standard offset after the transition in seconds * @return this, for chaining * @throws IllegalStateException if no window has yet been added * @throws IllegalStateException if the window already has fixed savings * @throws IllegalStateException if the window has reached the maximum capacity of 2000 rules */ public ZoneRulesBuilder addRuleToWindow( LocalDateTime transitionDateTime, TimeDefinition timeDefinition, int savingAmountSecs) { Jdk8Methods.requireNonNull(transitionDateTime, "transitionDateTime"); return addRuleToWindow( transitionDateTime.getYear(), transitionDateTime.getYear(), transitionDateTime.getMonth(), transitionDateTime.getDayOfMonth(), null, transitionDateTime.toLocalTime(), false, timeDefinition, savingAmountSecs); }
/** * 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 transitionDateTime the date-time that the transition occurs as defined by timeDefintion, not null * @param timeDefinition the definition of how to convert local to actual time, not null * @param savingAmountSecs the amount of saving from the standard offset after the transition in seconds * @return this, for chaining * @throws IllegalStateException if no window has yet been added * @throws IllegalStateException if the window already has fixed savings * @throws IllegalStateException if the window has reached the maximum capacity of 2000 rules */ public ZoneRulesBuilder addRuleToWindow( LocalDateTime transitionDateTime, TimeDefinition timeDefinition, int savingAmountSecs) { Jdk8Methods.requireNonNull(transitionDateTime, "transitionDateTime"); return addRuleToWindow( transitionDateTime.getYear(), transitionDateTime.getYear(), transitionDateTime.getMonth(), transitionDateTime.getDayOfMonth(), null, transitionDateTime.toLocalTime(), false, timeDefinition, savingAmountSecs); }