/** * Convenience method for parsing HL7 dates (treated just like a timestamp with only year, * month, and day specified) * * @see org.openmrs.hl7.HL7Util#parseHL7Timestamp(String) * @throws HL7Exception */ public static Date parseHL7Date(String s) throws HL7Exception { return parseHL7Timestamp(s); }
String timeZoneOffset = getTimeZoneOffset(s, new Date()); s = s.replace(timeZoneOffset, ""); // remove the timezone from the string
/** * @throws HL7Exception * @see HL7Util#parseHL7Timestamp(String) */ @Test public void parseHL7Timestamp_shouldHandle197804110615dash0200() throws HL7Exception { Date d = HL7Util.parseHL7Date("197804110615-0200"); Assert.assertEquals(new Long("261130500000"), (Long) d.getTime()); }
File destinationDir = HL7Util.getHl7ArchivesDirectory(); try {
/** * @throws HL7Exception * @see HL7Util#parseHL7Time(String) */ @Test @SuppressWarnings("deprecation") public void parseHL7Time_shouldHandle0615() throws HL7Exception { // set tz to be a __non DST__ timezone so this junit test works everywhere and always TimeZone originalTimeZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("EAT")); Date parsedDate = HL7Util.parseHL7Time("0615"); Assert.assertEquals(6, parsedDate.getHours()); Assert.assertEquals(15, parsedDate.getMinutes()); // reset the timezone TimeZone.setDefault(originalTimeZone); }
try { Date parsedDay = new SimpleDateFormat("yyyyMMdd").parse(s.substring(0, 8)); timeZoneOffset = getTimeZoneOffset(s, parsedDay);
/** * @throws HL7Exception * @see HL7Util#parseHL7Timestamp(String) */ @Test @SuppressWarnings("deprecation") public void parseHL7Timestamp_shouldNotFlubDstWith20091225123000() throws HL7Exception { // set tz to be US/Indianapolis so this junit test works everywhere and always TimeZone originalTimeZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("EST")); Date d = HL7Util.parseHL7Date("20091225003000"); Assert.assertEquals(25, d.getDate()); // reset the timezone TimeZone.setDefault(originalTimeZone); }
/** * @throws ParseException * @see HL7Util#getTimeZoneOffset(String,Date) */ @Test public void getTimeZoneOffset_shouldReturnTimezoneForGivenDateAndNotTheCurrentDate() throws ParseException { // set tz to be US/Indianapolis so this junit test works everywhere and always TimeZone originalTimeZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("GMT-05:00")); Assert.assertEquals("-0500", HL7Util.getTimeZoneOffset("197804110615", new SimpleDateFormat("yyyyMMdd") .parse("20091225"))); // reset the timezone TimeZone.setDefault(originalTimeZone); }
throw new HL7Exception("Missing birth date in an NK1 segment"); person.setBirthdate(HL7Util.parseHL7Timestamp(dateOfBirth.getTime().getValue()));
/** * @see HL7Util#getTimeZoneOffset(String,Date) */ @Test public void getTimeZoneOffset_shouldReturnTimezoneStringIfExistsInGivenString() { Assert.assertEquals("+1100", HL7Util.getTimeZoneOffset("348934934934+1100", new Date())); }