/** * Sets the end date. * * @param endDate The end date. */ private void setEndDate(String endDate) { this.rawEndDate = endDate; this.endDate = DateUtil.parseDate(endDate); }
/** * Parses an input value. * * @param value The value to parse. * @return The resulting date value if successful. * @throws ParseException Date parsing exception. */ public Date parse(String value) throws ParseException { return parseDate(value, pattern); } }
@Override protected Date _toValue(String value) { return DateUtil.parseDate(value); }
/** * Sets the start date. * * @param startDate The start date. */ private void setStartDate(String startDate) { this.rawStartDate = startDate; this.startDate = DateUtil.parseDate(startDate); }
@Override protected Date _toValue(String value) { return DateUtil.parseDate("01-Jan-1900 " + value); }
/** * Returns a date value if the input is a valid date. Otherwise, returns null. Explicitly * excludes some patterns that may successfully parse as a date. * * @param value Input to parse. * @return Result of parsed input, or null if parsing unsuccessful. */ private Date parseDate(String value) { if (StringUtils.isNumeric(value)) { return null; } if (value.matches("^\\d+-\\d+$")) { return null; } return DateUtil.parseDate(value); }
/** * Returns a date item associated with the specified item name. * * @param itemName Item name * @return Date value */ public Date getDate(String itemName) { try { return DateUtil.parseDate(getItem(itemName)); } catch (Exception e) { return null; } }
private void testDate(String value, Date expected, int threshold) { Date actual = DateUtil.parseDate(value); testDate(actual); long diff = Math.abs(expected.getTime() - actual.getTime()); assertTrue("Difference exceeded threshold " + diff + " (" + threshold + ")", diff <= threshold); }
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); }
@Test public void testDateUtil() { testDate(now()); testDate(today()); testDate("T", today(), 0); testDate("N", now(), 100); testDate("T+30", DateUtil.addDays(today(), 30, false), 0); testDate("N+30", DateUtil.addDays(now(), 30, false), 100); testDate("T-4", DateUtil.addDays(today(), -4, false), 0); testDate("T-50s", new Date(today().getTime() - 50000), 0); testDate("N-50s", new Date(now().getTime() - 50000), 100); testDate("T-50h", new Date(today().getTime() - 50 * 60 * 60 * 1000), 0); testDate("T-50n", new Date(today().getTime() - 50 * 60 * 1000), 0); Date date = DateUtil.parseDate("19880302"); testDate(date.toString(), date, 0); }
ssn.setValue("999-99-9999"); patient1.getIdentifier().add(ssn); patient1.setBirthDate(DateUtil.parseDate("1958-07-27")); Patient patient2 = new Patient(); patient2.setId("123"); ssn2.setValue("123-45-6789"); patient2.getIdentifier().add(ssn2); patient2.setBirthDate(DateUtil.parseDate("1963-05-01")); Object subscriber = new ContextChangeSubscriber(); // Create a patient context change subscriber