XformInstanceResource extends BaseResource<OpenmrsObject> { public static Date parseTimestamp(String timestamp) { List<String> acceptablePatterns = Arrays.asList( "yyyy-MM-dd'T'HH:mm:ss.SSSX", "yyyy-MM-dd'T'HH:mm:ssX", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd", "yyyyMMdd'T'HHmmss.SSSX", "yyyyMMdd'T'HHmmssX", "yyyyMMdd" ); for (String pattern : acceptablePatterns) { try { return new SimpleDateFormat(pattern).parse(timestamp); } catch (ParseException e) { LOG.warn("Unparseable encounter_datetime: " + timestamp); } } return null; } XformInstanceResource(); Document getPreparedXformDocument(SimpleObject post); static Date parseTimestamp(String timestamp);  }
@Test public void parseNonstandardTimestamp() { String input = "20141120T092547.373Z"; String expected = "2014-11-20T09:25:47.373Z"; String actual = Utils.formatUtc8601(XformInstanceResource.parseTimestamp(input)); assertEquals(expected, actual); }
@Test public void parseStandardTimestamp() { String input = "2014-11-20T09:25:47.373Z"; String expected = "2014-11-20T09:25:47.373Z"; String actual = Utils.formatUtc8601(XformInstanceResource.parseTimestamp(input)); assertEquals(expected, actual); }