Package org.zkoss.zul

Class ZonedDateTimeRange

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<ZonedDateTimeRange>

    public final class ZonedDateTimeRange
    extends java.lang.Object
    implements java.io.Serializable, java.lang.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:
    10.4.0
    Author:
    peaker
    See Also:
    Serialized Form
    • Constructor Detail

      • ZonedDateTimeRange

        public ZonedDateTimeRange​(java.time.ZonedDateTime begin,
                                  java.time.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 Detail

      • getBegin

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

        public java.time.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​(java.time.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 java.time.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​(java.lang.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 java.lang.Object
      • hashCode

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

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object