Package org.zkoss.zul

Class SimpleDateConstraint

    • Constructor Detail

      • SimpleDateConstraint

        public SimpleDateConstraint​(int flags)
      • SimpleDateConstraint

        public SimpleDateConstraint​(java.util.regex.Pattern regex,
                                    java.lang.String errmsg)
        Constructs a regular-expression constraint.
        Parameters:
        regex - ignored if null or empty
        errmsg - the error message to display. Ignored if null or empty.
        Since:
        8.0.1
      • SimpleDateConstraint

        public SimpleDateConstraint​(int flags,
                                    java.util.regex.Pattern regex,
                                    java.lang.String errmsg)
        Constructs a constraint combining regular expression.
        Parameters:
        flags - a combination of SimpleConstraint.NO_POSITIVE, SimpleConstraint.NO_NEGATIVE, SimpleConstraint.NO_ZERO, and so on.
        regex - ignored if null or empty
        errmsg - the error message to display. Ignored if null or empty.
        Since:
        8.0.1
      • SimpleDateConstraint

        public SimpleDateConstraint​(int flags,
                                    java.util.Date begin,
                                    java.util.Date end,
                                    java.lang.String errmsg)
        Constructs a constraint with beginning and ending date.
        Parameters:
        flags - a combination of SimpleConstraint.NO_POSITIVE, SimpleConstraint.NO_NEGATIVE, SimpleConstraint.NO_ZERO, and so on.
        begin - the beginning date, or null if no constraint at the beginning date.
        end - the ending date, or null if no constraint at the ending date.
        errmsg - the error message to display. Ignored if null or empty.
      • SimpleDateConstraint

        public SimpleDateConstraint​(java.lang.String constraint)
        Constructs a constraint with a list of constraints separated by comma.
        Parameters:
        constraint - a list of constraints separated by comma. Example: "between 20071012 and 20071223", "before 20080103"
    • Method Detail

      • forTimeZone

        public static SimpleDateConstraint forTimeZone​(java.lang.String constraint,
                                                       java.util.TimeZone tzone)
        Builds a SimpleDateConstraint whose date literals are parsed in tzone instead of the JVM default. Use this from components that expose their own timeZone property so the constraint bounds line up with the component's interpretation of "midnight" — e.g. a Daterangebox configured for Asia/Tokyo parsing "before 20260101" should anchor the bound to midnight Tokyo time, not the server's JVM default.

        This works because SimpleConstraint parses lazily: the date literals are only consumed on the first validate(org.zkoss.zk.ui.Component, java.lang.Object) call. The AbstractSimpleDateTimeConstraint.setTimeZone(TimeZone) override resets the lazy-parse flag immediately after construction, so by the time parseFrom(java.lang.String) runs the right zone is in place.

        Limitation. The supplied tzone controls how the constraint's own date literals are parsed and how the candidate value is normalised in AbstractSimpleDateTimeConstraint.validate0(org.zkoss.zk.ui.Component, T), but the NO_PAST / NO_FUTURE / NO_TODAY flag checks performed by super.validate compare against Dates.today() — i.e. today in the JVM-default zone — not against today-in-tzone. Near the date-line a value that is "today" in tzone can be "yesterday" or "tomorrow" in the JVM zone, so the flag verdict may differ from a user's zone-aware expectation. A fully zone-aware today-flag check is tracked as a separate enhancement.

        Since:
        10.4.0
      • parseFrom

        protected java.util.Date parseFrom​(java.lang.String val)
                                    throws org.zkoss.zk.ui.UiException
        Specified by:
        parseFrom in class AbstractSimpleDateTimeConstraint<java.util.Date>
        Throws:
        org.zkoss.zk.ui.UiException
      • validate

        public void validate​(org.zkoss.zk.ui.Component comp,
                             java.lang.Object value)
                      throws org.zkoss.zk.ui.WrongValueException
        Description copied from interface: Constraint
        Verifies whether the value is acceptable.
        Specified by:
        validate in interface Constraint
        Overrides:
        validate in class AbstractSimpleDateTimeConstraint<java.util.Date>
        Parameters:
        comp - the component being validated
        Throws:
        org.zkoss.zk.ui.WrongValueException
      • validateRange

        public void validateRange​(org.zkoss.zk.ui.Component comp,
                                  java.util.Date begin,
                                  java.util.Date end)
                           throws org.zkoss.zk.ui.WrongValueException
        Validates a date range against this constraint's begin / end bounds.

        Semantics — per-endpoint, not range-as-whole. The single-value validate(Component, Object) is applied to begin and to end independently. A "between 20260101 and 20261231" constraint accepts (2026-03-01, 2026-09-01) because each endpoint individually falls within the bound; it does NOT check whether the (begin, end) pair as a unit satisfies any cross-bound predicate (e.g. "the range must be wholly inside Q2"). Callers that need cross-bound rules should add them in their own component (Daterangebox uses minNights/maxNights properties for that purpose).

        Either end may be null for open-ended ranges. When both are non-null, the range is also required to be non-reversed (beginend). Asymmetry with single-value validate(Component, Object): a null endpoint here is silently skipped (so NO_EMPTY does not fire for it). Emptiness for range-aware components is governed by the component's own allowEmpty property, not by base-class flags.

        Note: both ends are normalised via Dates.beginOfDate(java.util.Date, java.util.TimeZone) before validation, so the time-of-day component is ignored. A constraint such as "before 2026-01-01 12:00" will be treated as "before 2026-01-01" for the end-of-range check — matching the existing single-value validate(Component, Object) behaviour.

        Parameters:
        comp - the component (used for error message context)
        begin - the begin date, or null if unbounded
        end - the end date, or null if unbounded
        Throws:
        org.zkoss.zk.ui.WrongValueException - if either bound violates the constraint, or if begin is later than end
        Since:
        10.4.0