Class ZoneRulesBuilder.TZWindow

  • Enclosing class:
    ZoneRulesBuilder

    class ZoneRulesBuilder.TZWindow
    extends java.lang.Object
    A definition of a window in the time-line. The window will have one standard offset and will either have a fixed DST savings or a set of rules.
    • Field Detail

      • standardOffset

        private final ZoneOffset standardOffset
        The standard offset during the window, not null.
      • windowEnd

        private final LocalDateTime windowEnd
        The end local time, not null.
      • fixedSavingAmountSecs

        private java.lang.Integer fixedSavingAmountSecs
        The fixed amount of the saving to be applied during this window.
      • maxLastRuleStartYear

        private int maxLastRuleStartYear
        The latest year that the last year starts at.
    • Constructor Detail

      • TZWindow

        TZWindow​(ZoneOffset standardOffset,
                 LocalDateTime windowEnd,
                 ZoneOffsetTransitionRule.TimeDefinition timeDefinition)
        Constructor.
        Parameters:
        standardOffset - the standard offset applicable during the window, not null
        windowEnd - the end of the window, relative to the time definition, null if forever
        timeDefinition - the time definition for calculating the true end, not null
    • Method Detail

      • setFixedSavings

        void setFixedSavings​(int fixedSavingAmount)
        Sets the fixed savings amount for the window.
        Parameters:
        fixedSavingAmount - the amount of daylight saving to apply throughout the window, may be null
        Throws:
        java.lang.IllegalStateException - if the window already has rules
      • addRule

        void addRule​(int startYear,
                     int endYear,
                     Month month,
                     int dayOfMonthIndicator,
                     DayOfWeek dayOfWeek,
                     LocalTime time,
                     int adjustDays,
                     ZoneOffsetTransitionRule.TimeDefinition timeDefinition,
                     int savingAmountSecs)
        Adds a rule to the current window.
        Parameters:
        startYear - the start year of the rule, from MIN_VALUE to MAX_VALUE
        endYear - the end year of the rule, from MIN_VALUE to MAX_VALUE
        month - the month of the transition, not null
        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
        dayOfWeek - the day-of-week to adjust to, null if day-of-month should not be adjusted
        time - the time that the transition occurs as defined by timeDefintion, not null
        adjustDays - the time days adjustment
        timeDefinition - the definition of how to convert local to actual time, not null
        savingAmountSecs - the amount of saving from the standard offset in seconds
        Throws:
        java.lang.IllegalStateException - if the window already has fixed savings
        java.lang.IllegalStateException - if the window has reached the maximum capacity of 2000 rules
      • validateWindowOrder

        void validateWindowOrder​(ZoneRulesBuilder.TZWindow previous)
        Validates that this window is after the previous one.
        Parameters:
        previous - the previous window, not null
        Throws:
        java.lang.IllegalStateException - if the window order is invalid
      • tidy

        void tidy​(int windowStartYear)
        Adds rules to make the last rules all start from the same year. Also add one more year to avoid weird case where penultimate year has odd offset.
        Parameters:
        windowStartYear - the window start year
        Throws:
        java.lang.IllegalStateException - if there is only one rule defined as being forever
      • isSingleWindowStandardOffset

        boolean isSingleWindowStandardOffset()
        Checks if the window is empty.
        Returns:
        true if the window is only a standard offset
      • createWallOffset

        ZoneOffset createWallOffset​(int savingsSecs)
        Creates the wall offset for the local date-time at the end of the window.
        Parameters:
        savingsSecs - the amount of savings in use in seconds
        Returns:
        the created date-time epoch second in the wall offset, not null
      • createDateTimeEpochSecond

        long createDateTimeEpochSecond​(int savingsSecs)
        Creates the offset date-time for the local date-time at the end of the window.
        Parameters:
        savingsSecs - the amount of savings in use in seconds
        Returns:
        the created date-time epoch second in the wall offset, not null