/** * 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. * @return Formatted string representation of the specified date, or an empty string if date is * null. */ public static String formatDate(Date date) { return formatDate(date, false, false); }
/** * 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. * @return Formatted string representation of the specified date, or an empty string if date is * null. */ public static String formatDate(Date date, boolean showTimezone) { return formatDate(date, showTimezone, false); }
/** * Same as formatDate(Date, boolean) except replaces the time separator with the specified * string. * * @param date Date value to convert * @param timeSeparator String to use in place of default time separator * @return Formatted string representation of the specified date using the specified time * separator. */ public static String formatDate(Date date, String timeSeparator) { return formatDate(date).replaceFirst(" ", timeSeparator); }
/** * Create a date range from individual components. * * @param label Displayable text. If null, a default label is created. * @param startDate The start date. * @param endDate The end date. */ public DateRange(String label, Date startDate, Date endDate) { this.startDate = startDate; this.endDate = endDate; this.rawStartDate = DateUtil.formatDate(startDate); this.rawEndDate = DateUtil.formatDate(endDate); checkDates(); this.label = label != null ? label : (rawStartDate + " to " + rawEndDate); }
/** * Returns the current date in standard format. * * @return Timestamp for current date. */ public String getTimestamp() { return DateUtil.formatDate(DateUtil.stripTime(new Date())); }
@Override protected String getValue() { return DateUtil.formatDate(editor.getValue()); }
private String formatDateAndAge(Date date) { return date == null ? null : DateUtil.formatDate(date) + " (" + DateUtil.formatAge(date) + ")"; }
/** * Add a row containing the specified header (left column) and value (right column). * * @param header Text for header column * @param value Date object */ protected void addRow(String header, Date value) { try { addRow(header, DateUtil.formatDate(value)); } catch (Exception e) { log.error(e.getMessage(), e); addRow(header, e.getMessage()); } }
/** * Sets the current date value. * * @param date The date value. */ public void setDate(Date date) { validateDate(date); setValue(DateUtil.formatDate(date)); }
/** * Adds a message to the dialog panel. * * @param chatMessage Message to add. * @param self True if this user is the message author. */ private void addDialog(ChatMessage chatMessage, boolean self) { if (chatMessage != null) { String header = chatMessage.sender.getUserName() + " @ " + DateUtil.formatDate(chatMessage.timestamp); addDialog(header, chatMessage.message, self); } }
public String createLabelText(Object value, String prefix) { String text = StringUtils.trimToEmpty(value == null ? null : value instanceof Collection ? createLabelText((Collection<?>) value) : value instanceof Date ? DateUtil.formatDate((Date) value) : value instanceof String ? StrUtil.formatMessage((String) value) : value.toString()); return text.isEmpty() ? "" : StrUtil.formatMessage(StringUtils.defaultString(prefix)) + text; }
/** * Initialize the token consumer. A token consumer replaces its associated token with a computed * value and writes the result to the output stream. */ private void initTokenConsumers() { tokens.put("${schema-name}", (token, value) -> { for (String schema : schemas) { write(value.replace(token, schema)); } }); tokens.put("${schema-version}", (token, value) -> { write(value.replace(token, SchemaGenerator.formatVersion(version))); }); tokens.put("${app-version}", (token, value) -> { write(value.replace(token, version)); }); tokens.put("${generated-on}", (token, value) -> { write(value.replace(token, DateUtil.formatDate(new Date()))); }); }
private void doTestFormatting(String time, String expected) throws Exception { SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy" + (time.length() == 0 ? "" : " HH:mm")); Date date = formatter.parse(DATE + time); assertEquals(DateUtil.formatDate(date), DATE + expected); }
/** * Adds a demographic element to the demographic panel. * * @param root Root component. * @param labelId The id of the label to use. * @param object The element to be added. * @param style CSS styling to apply to element (may be null). */ protected void addDemographic(BaseUIComponent root, String labelId, Object object, String style) { object = object instanceof PrimitiveType ? ((PrimitiveType<?>) object).getValue() : object; String value = object == null ? null : object instanceof Date ? DateUtil.formatDate((Date) object) : object.toString().trim(); if (!StringUtils.isEmpty(value)) { Label lbl = new Label((labelId == null ? "" : getDemographicLabel(labelId) + ": ") + value); root.addChild(lbl); if (style != null) { lbl.addStyles(style); } } }
private void testDate(Date date, boolean showTimezone, boolean ignoreTime) { String text = DateUtil.formatDate(date, showTimezone, ignoreTime); print(text); Date date2 = DateUtil.parseDate(text); String text2 = DateUtil.formatDate(date2, showTimezone, ignoreTime); assertEquals(text, text2); }
private void testDateFormat(String tz, String time) throws Exception { SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm zzz"); Date date = formatter.parse(DATE + " 13:04 EST"); // Reference date/time is 21-Nov-1978 13:04 EST TimeZone.setDefault(TimeZone.getTimeZone(tz)); String DATE_TIME_NOTZ = DATE + " " + time; String DATE_TIME_TZ = DATE_TIME_NOTZ + " " + tz; assertEquals(DATE_TIME_TZ, DateUtil.formatDate(date, true)); assertEquals(DATE_TIME_NOTZ, DateUtil.formatDate(date)); assertEquals(DATE, DateUtil.formatDate(date, true, true)); assertEquals(DATE_TIME_NOTZ, DateUtil.formatDate(date, false)); assertEquals(DATE_TIME_NOTZ, DateUtil.formatDate(date, false, false)); formatter = new SimpleDateFormat("dd-MMM-yyyy"); date = formatter.parse(DATE); assertEquals(DATE, DateUtil.formatDate(date, true)); assertEquals(DATE, DateUtil.formatDate(date)); assertEquals(DATE, DateUtil.formatDate(date, true, true)); assertEquals(DATE, DateUtil.formatDate(date, false)); assertEquals(DATE, DateUtil.formatDate(date, false, false)); }
/** * Retrieves a formatted header for the current patient. * * @return Formatted header. */ public String getPatientInfo() { Patient patient = PatientContext.getActivePatient(); String text; if (patient == null) { text = "No Patient Selected"; } else { Identifier mrn = FhirUtil.getMRN(patient); // May be null! text = FhirUtil.formatName(patient.getName()); if (mrn != null) { text += " #" + mrn.getValue(); } String gender = patient.hasGender() ? patient.getGender().getDisplay() : ""; if (!StringUtils.isEmpty(gender)) { text += " (" + gender + ")"; } Date deceased = patient.getDeceased() instanceof DateType ? ((DateType) patient.getDeceased()).getValue() : null; String age = DateUtil.formatAge(patient.getBirthDate(), true, deceased); text += " Age: " + age; if (deceased != null) { text += " Died: " + DateUtil.formatDate(deceased); } } return text; }
info = dob == null ? "" : DateUtil.formatDate(dob);