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.
      • fixedSavingAmount

        private Period fixedSavingAmount
        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,
                 ZoneRulesBuilder.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​(Period 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,
                     MonthOfYear month,
                     int dayOfMonthIndicator,
                     DayOfWeek dayOfWeek,
                     LocalTime time,
                     boolean timeEndOfDay,
                     ZoneRulesBuilder.TimeDefinition timeDefinition,
                     Period savingAmount)
        Adds a rule to the current window.
        Parameters:
        startYear - the start year of the rule, from MIN_YEAR to MAX_YEAR
        endYear - the end year of the rule, from MIN_YEAR to MAX_YEAR
        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
        timeEndOfDay - whether midnight is at the end of day
        timeDefinition - the definition of how to convert local to actual time, not null
        savingAmount - the amount of saving from the standard offset, not null
        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
      • createDateTime

        OffsetDateTime createDateTime​(Period savings)
        Creates the offset date-time for the local date-time at the end of the window.
        Parameters:
        savings - the amount of savings in use, not null
        Returns:
        the created offset date-time in the wall offset, never null