/** * Validates that a time component exists if one is required. * * @param value The date value. */ public void validateDate(Date value) { if (requireTime && !DateUtil.hasTime(value)) { throw new IllegalArgumentException(requireTimeError); } }
/** * Convert a date to HL7 format. * * @param date Date to convert. * @return The HL7-formatted date. */ public static String toHL7(Date date) { Format format = hasTime(date) ? Format.HL7_WITHOUT_TIME : Format.HL7; return format.format(date); }
/** * Converts a date/time value to a string, using the format dd-mmm-yyyy hh:mm. Because we cannot * determine the absence of a time from a time of 24:00, we must assume a time of 24:00 means * that no time is present and strip that from the return value. * * @param date Date value to convert * @param showTimezone If true, time zone information is also appended. * @param ignoreTime If true, the time component is ignored. * @return Formatted string representation of the specified date, or an empty string if date is * null. */ public static String formatDate(Date date, boolean showTimezone, boolean ignoreTime) { ignoreTime = ignoreTime || !hasTime(date); Format format = ignoreTime ? Format.WITHOUT_TIME : showTimezone ? Format.WITH_TZ : Format.WITHOUT_TZ; return format.format(date); }
/** * Transfers input state between the input box and the drop down dialog. If drop down is true, * the date value from the input box is copied to the drop down. If false, the reverse is done. * * @param open The state of the drop down dialog. */ private void update(boolean open) { if (open) { datebox.setFocus(true); datebox.selectAll(); Date date = getDate(); updateDatebox(date); updateTimebox(DateUtil.hasTime(date) ? date : null); clearError(); } else if (ok) { Date date = DateTimeUtil.getTime(datebox, timebox); date = timebox.getValue() != null ? DateUtils.setMilliseconds(date, 1) : date; setDate(date); } }