Package org.zkoss.zul

Class ZonedDateTimeRange

java.lang.Object
org.zkoss.zul.ZonedDateTimeRange
All Implemented Interfaces:
Serializable, Comparable<ZonedDateTimeRange>

public final class ZonedDateTimeRange extends Object implements Serializable, Comparable<ZonedDateTimeRange>
An immutable ZonedDateTime-based range, the java.time counterpart to DateRange for time-zone-aware scenarios.

Equality and ordering compare ZonedDateTime values directly, which means two ranges with the same instant but different zones are not equal. contains(ZonedDateTime) and overlaps(ZonedDateTimeRange) compare by absolute instant (ChronoZonedDateTime.isBefore(java.time.chrono.ChronoZonedDateTime)) and therefore work correctly across zones.

Since:
11.0.0
Author:
peaker
See Also:
  • Constructor Details

    • ZonedDateTimeRange

      public ZonedDateTimeRange(ZonedDateTime begin, ZonedDateTime end)
      Constructs a new range. Either end may be null.
      Parameters:
      begin - the begin instant (inclusive), or null
      end - the end instant (inclusive), or null
  • Method Details

    • of

      public static ZonedDateTimeRange of(ZonedDateTime begin, ZonedDateTime end)
      Parameters:
      begin - the begin instant, or null
      end - the end instant, or null
      Returns:
      a new ZonedDateTimeRange
    • getBegin

      public ZonedDateTime getBegin()
      Returns:
      the begin instant, or null
    • getEnd

      public ZonedDateTime getEnd()
      Returns:
      the end instant, or null
    • isEmpty

      public boolean isEmpty()
      Returns:
      true if both ends are null.
    • isOpenStart

      public boolean isOpenStart()
      Returns:
      true if only begin is null.
    • isOpenEnd

      public boolean isOpenEnd()
      Returns:
      true if only end is null.
    • isClosed

      public boolean isClosed()
      Returns:
      true if both ends are non-null.
    • contains

      public boolean contains(ZonedDateTime value)
      Inclusive, instant-based containment test (null-safe).
      Parameters:
      value - the instant to test
      Returns:
      true if value is in the range
    • getDuration

      public Duration getDuration()
      Returns the Duration between begin and end for a closed range, or null otherwise.
      Returns:
      the duration, or null for non-closed ranges
    • overlaps

      public boolean overlaps(ZonedDateTimeRange other)
      Instant-based, null-safe overlap test.
      Parameters:
      other - the other range
      Returns:
      true if the two share at least one instant
    • equals

      public boolean equals(Object o)
      Zone-identity semantics. Equality delegates to ZonedDateTime.equals(Object), which compares the local date-time and the zone — two ranges representing the same instants in different zones (e.g. 2026-01-01T12:00+09:00 vs 2026-01-01T03:00Z) are not equal here, even though contains(ZonedDateTime) and overlaps(ZonedDateTimeRange) would treat them as equivalent (those use instant-based isBefore/isAfter). Bind-driven dirty checks that re-set the value to an instant-equivalent but zone-different range will therefore see the property as changed.
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Overrides:
      toString in class Object
    • compareTo

      public int compareTo(ZonedDateTimeRange o)
      Specified by:
      compareTo in interface Comparable<ZonedDateTimeRange>