private WrongValueException outOfRangeValue(Component comp) { final String errmsg = getErrorMessage(comp); if (errmsg != null) return new WrongValueException(comp, errmsg); final String s = _beg != null ? _end != null ? dateToString(comp, _beg, _tzone) + " ~ " + dateToString(comp, _end, _tzone) : ">= " + dateToString(comp, _beg, _tzone) : "<= " + dateToString(comp, _end, _tzone); return new WrongValueException(comp, MZul.OUT_OF_RANGE, s); }
/** Constructs a regular-expression constraint. * * @param regex ignored if null or empty * @param errmsg the error message to display. Ignored if null or empty. * @since 8.0.1 */ public SimpleDateConstraint(Pattern regex, String errmsg) { super(regex, errmsg); fixConstraint(); }
/** * @param constr a list of constraints separated by comma. * Example: "between 20071012 and 20071223", "before 20080103" */ // -- super --// public void setConstraint(String constr) { SimpleDateConstraint sc = null; if (constr != null) { sc = new SimpleDateConstraint(constr); sc.setTimeZone(this.getTimeZone()); } setConstraint(sc); // Bug 2564298 }
private static String dateToString(Component comp, Date d, TimeZone tzone) { if (d == null) return ""; if (comp instanceof Datebox) return ((Datebox) comp).coerceToString(d); return getDateFormat(tzone).format(d); } }
public void setConstraint(Constraint constr) { if (!Objects.equals(_constraint, constr)) { _constraint = (SimpleDateConstraint) constr; smartUpdate("constraint", new JavaScriptValue(_constraint.getClientConstraint())); } }
public void validate(Component comp, Object value) throws WrongValueException { super.validate(comp, value); if (value instanceof Date) { final Date d = Dates.beginOfDate((Date) value, _tzone); if (_beg != null && _beg.compareTo(d) > 0) { throw outOfRangeValue(comp); } if (_end != null && _end.compareTo(d) < 0) { throw outOfRangeValue(comp); } } }
/** * Sets a list of constraints separated by comma. * Example: "between 20071012 and 20071223", "before 20080103". * @param constr a list of constraints separated by comma. */ public void setConstraint(String constr) { if (constr != null) { setConstraint(new SimpleDateConstraint(constr)); } }
protected int parseConstraint(String constraint) throws UiException { if (constraint.startsWith("between")) { final int j = constraint.indexOf("and", 7); if (j < 0) throw new UiException("Constraint syntax error: " + constraint); _beg = parseDate(constraint.substring(7, j), _tzone); _end = parseDate(constraint.substring(j + 3), _tzone); if (_beg.compareTo(_end) > 0) { final Date d = _beg; _beg = _end; _end = d; } return 0; } else if (constraint.startsWith("before") && !constraint.startsWith("before_")) { _end = parseDate(constraint.substring(6), _tzone); return 0; } else if (constraint.startsWith("after") && !constraint.startsWith("after_")) { _beg = parseDate(constraint.substring(5), _tzone); return 0; } return super.parseConstraint(constraint); }
/** Sets the time zone that this date box belongs to, or null if * the default time zone is used. * <p>The default time zone is determined by {@link TimeZones#getCurrent}. * * <p>Notice that if {@link #getDisplayedTimeZones} was called with * a non-empty list, the time zone must be one of it. * Otherwise (including <code>tzone</tt> is null), * the first timezone is selected. */ public void setTimeZone(TimeZone tzone) { if (_tzone != tzone) { if (_dtzones != null) { _tzone = _dtzones.contains(tzone) ? tzone : _dtzones.get(0); } else { _tzone = tzone; } SimpleDateConstraint cst = ((SimpleDateConstraint) this.getConstraint()); if (cst != null) cst.setTimeZone(_tzone); smartUpdate("timeZone", _tzone.getID()); smartUpdate("_value", marshall(_value)); } }
private static Date parseDate(String val, TimeZone tzone) throws UiException { try { return getDateFormat(tzone).parse(val.trim()); } catch (ParseException ex) { throw new UiException("Not a date: " + val + ". Format: yyyyMMdd", ex); } }
protected void renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer) throws java.io.IOException { super.renderProperties(renderer); if (_name != null) render(renderer, "name", _name); render(renderer, "defaultTzone", _defaultTzone.getID()); render(renderer, "weekOfYear", _weekOfYear); render(renderer, "value", _value); render(renderer, "showTodayLink", _showTodayLink); render(renderer, "todayLinkLabel", _todayLinkLabel); if (_constraint != null) { render(renderer, "constraint", new JavaScriptValue(_constraint.getClientConstraint())); } } }
/** Constructs a constraint combining regular expression. * * @param flags a combination of {@link #NO_POSITIVE}, {@link #NO_NEGATIVE}, * {@link #NO_ZERO}, and so on. * @param regex ignored if null or empty * @param errmsg the error message to display. Ignored if null or empty. * @since 8.0.1 */ public SimpleDateConstraint(int flags, Pattern regex, String errmsg) { super(flags, regex, errmsg); fixConstraint(); }
/** Constructs a constraint with a list of constraints separated by comma. * * @param constraint a list of constraints separated by comma. * Example: "between 20071012 and 20071223", "before 20080103" */ public SimpleDateConstraint(String constraint) { super(constraint); fixConstraint(); }
/** Constraints a constraint. * * @param flags a combination of {@link #NO_POSITIVE}, {@link #NO_NEGATIVE}, * {@link #NO_ZERO}, and so on. * @param errmsg the error message to display. Ignored if null or empty. */ public SimpleDateConstraint(int flags, String errmsg) { super(flags, errmsg); fixConstraint(); }
public SimpleDateConstraint(int flags) { super(flags); fixConstraint(); }
/** Constructs a constraint with beginning and ending date. * * @param flags a combination of {@link #NO_POSITIVE}, {@link #NO_NEGATIVE}, * {@link #NO_ZERO}, and so on. * @param begin the beginning date, or null if no constraint at the beginning * date. * @param end the ending date, or null if no constraint at the ending * date. * @param errmsg the error message to display. Ignored if null or empty. */ public SimpleDateConstraint(int flags, Date begin, Date end, String errmsg) { super(flags, errmsg); _beg = begin; _end = end; fixConstraint(); }
/** Constructs a regular-expression constraint. * * @param regex ignored if null or empty. Unlike constraint, the regex doesn't need to enclose with '/'. * @param errmsg the error message to display. Ignored if null or empty. * @deprecated As of release 8.0.1, replaced with {@link #SimpleDateConstraint(Pattern, String)} */ public SimpleDateConstraint(String regex, String errmsg) { super(regex == null || regex.length() == 0 ? null : Pattern.compile(regex), errmsg); fixConstraint(); }
/** Constructs a constraint combining regular expression. * * @param flags a combination of {@link #NO_POSITIVE}, {@link #NO_NEGATIVE}, * {@link #NO_ZERO}, and so on. * @param regex ignored if null or empty. Unlike constraint, the regex doesn't need to enclose with '/'. * @param errmsg the error message to display. Ignored if null or empty. * @deprecated As of release 8.0.1, replaced with {@link #SimpleDateConstraint(int, Pattern, String)} */ public SimpleDateConstraint(int flags, String regex, String errmsg) { super(flags, regex == null || regex.length() == 0 ? null : Pattern.compile(regex), errmsg); fixConstraint(); }