Class ZoneRules

java.lang.Object
dev.gmitch215.bytebox.time.ZoneRules

public final class ZoneRules extends Object
What a zone's offset was, and when it changed.

This is java.time.zone.ZoneRules, and it is here rather than taken from the implementation underneath because that one can only be subclassed from inside its own package, and the rules on this platform come from IntlZoneRules rather than from a rule table. Replacing it also leaves the table reader, the rule builder and the binary format unreachable.

of(ZoneOffset) builds the fixed rules a bare offset has, which is the case ZoneOffset.getRules() needs. The five-argument form builds rules from a transition history and refuses, because a history is what this platform does not have to give.

Final, and a zone is carried in a field rather than in a subclass. A subclass would have to name this class as its supertype, which is the one name a substitute may not use: the compiler translates java.time.zone.ZoneRules into a copy of this class under the original name, while a subclass goes on extending this one, and the two are unrelated wasm types. The symptom is a CompileError from the engine naming a method that returns one where the other is declared, so javac refusing the subclass is the cheaper failure.

Since:
1.0.0
  • Method Details

    • of

      public static ZoneRules of(ZoneOffset offset)
      The rules of a zone that is only ever one offset.
      Parameters:
      offset - the offset
      Returns:
      rules that always answer with it
    • of

      public static ZoneRules of(ZoneOffset baseStandardOffset, ZoneOffset baseWallOffset, List<ZoneOffsetTransition> standardOffsetTransitionList, List<ZoneOffsetTransition> transitionList, List<ZoneOffsetTransitionRule> lastRules)
      Rules assembled from a transition history, which is not available here.
      Parameters:
      baseStandardOffset - the standard offset before the history starts
      baseWallOffset - the wall offset before the history starts
      standardOffsetTransitionList - changes to the standard offset
      transitionList - the transitions
      lastRules - the recurring rules
      Returns:
      never
      Throws:
      UnsupportedOperationException - always
    • isFixedOffset

      public boolean isFixedOffset()
      Returns whether the offset never varies.
      Returns:
      whether the offset never varies
    • getOffset

      public ZoneOffset getOffset(Instant instant)
      The offset at an instant.
      Parameters:
      instant - the instant
      Returns:
      the offset
    • getOffset

      public ZoneOffset getOffset(LocalDateTime localDateTime)
      The offset that applies to a wall-clock reading, preferring the earlier one where it happens twice and the one after the change where it does not happen at all.
      Parameters:
      localDateTime - the reading
      Returns:
      the offset
    • getValidOffsets

      public List<ZoneOffset> getValidOffsets(LocalDateTime localDateTime)
      Every offset a wall-clock reading could mean: none in a gap, two in an overlap, otherwise one.
      Parameters:
      localDateTime - the reading
      Returns:
      the offsets, earliest first
    • getTransition

      public ZoneOffsetTransition getTransition(LocalDateTime localDateTime)
      The change a wall-clock reading falls inside.
      Parameters:
      localDateTime - the reading
      Returns:
      the change, or null when the reading is an ordinary one
    • getStandardOffset

      public ZoneOffset getStandardOffset(Instant instant)
      The offset the zone keeps when daylight saving is not in force.
      Parameters:
      instant - the instant
      Returns:
      the offset
    • getDaylightSavings

      public Duration getDaylightSavings(Instant instant)
      How far daylight saving has moved the clock.
      Parameters:
      instant - the instant
      Returns:
      the amount, zero when it is not in force
    • isDaylightSavings

      public boolean isDaylightSavings(Instant instant)
      Whether daylight saving is in force.
      Parameters:
      instant - the instant
      Returns:
      whether it is
    • isValidOffset

      public boolean isValidOffset(LocalDateTime localDateTime, ZoneOffset offset)
      Whether a wall-clock reading and an offset go together.
      Parameters:
      localDateTime - the reading
      offset - the offset
      Returns:
      whether they do
    • nextTransition

      public ZoneOffsetTransition nextTransition(Instant instant)
      The next change after an instant.
      Parameters:
      instant - the instant
      Returns:
      the change, or null when none is scheduled
    • previousTransition

      public ZoneOffsetTransition previousTransition(Instant instant)
      The last change before an instant.
      Parameters:
      instant - the instant
      Returns:
      the change, or null when there was none
    • getTransitions

      public List<ZoneOffsetTransition> getTransitions()
      Returns every recorded change.
      Returns:
      every recorded change
    • getTransitionRules

      public List<ZoneOffsetTransitionRule> getTransitionRules()
      Returns the rules by which changes recur.
      Returns:
      the rules by which changes recur
    • equals

      public boolean equals(Object otherRules)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object