@Test void parseDate() throws ParseException { Date newDate = new Date(); DateFormat format = new SimpleDateFormat(DateXarObjectPropertySerializer.DEFAULT_FORMAT); String string = format.format(newDate); Date formattedDate = format.parse(string); assertEquals(formattedDate, DateXarObjectPropertySerializer.parseDate(string)); }
public static Date parseDate(String source) { SimpleDateFormat format = new SimpleDateFormat(DEFAULT_FORMAT); try { return format.parse(source); } catch (ParseException e) { SimpleDateFormat sdfOld = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy", Locale.US); LOGGER.warn("Failed to parse date [{}] using format [{}]. Trying again with format [{}].", source, DEFAULT_FORMAT, sdfOld.toPattern()); try { return sdfOld.parse(source); } catch (ParseException exception) { LOGGER.warn("Failed to parse date [{}] using format [{}]. Defaulting to the current date.", source, sdfOld.toPattern()); return new Date(); } } }
DateXarObjectPropertySerializer implements XarObjectPropertySerializer { public static Date parseDate(String source) { SimpleDateFormat format = new SimpleDateFormat(DEFAULT_FORMAT); try { return format.parse(source); } catch (ParseException e) { SimpleDateFormat sdfOld = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy", Locale.US); LOGGER.warn("Failed to parse date [{}] using format [{}]. Trying again with format [{}].", source, DEFAULT_FORMAT, sdfOld.toPattern()); try { return sdfOld.parse(source); } catch (ParseException exception) { LOGGER.warn("Failed to parse date [{}] using format [{}]. Defaulting to the current date.", source, sdfOld.toPattern()); return new Date(); } } } }
DateXarObjectPropertySerializer implements XarObjectPropertySerializer { public static Date parseDate(String source) { SimpleDateFormat format = new SimpleDateFormat(DEFAULT_FORMAT); try { return format.parse(source); } catch (ParseException e) { SimpleDateFormat sdfOld = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy", Locale.US); LOGGER.warn("Failed to parse date [{}] using format [{}]. Trying again with format [{}].", source, DEFAULT_FORMAT, sdfOld.toPattern()); try { return sdfOld.parse(source); } catch (ParseException exception) { LOGGER.warn("Failed to parse date [{}] using format [{}]. Defaulting to the current date.", source, sdfOld.toPattern()); return new Date(); } } }  }
DateXarObjectPropertySerializer implements XarObjectPropertySerializer { public static Date parseDate(String source) { SimpleDateFormat format = new SimpleDateFormat(DEFAULT_FORMAT); try { return format.parse(source); } catch (ParseException e) { SimpleDateFormat sdfOld = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy", Locale.US); LOGGER.warn("Failed to parse date [{}] using format [{}]. Trying again with format [{}].", source, DEFAULT_FORMAT, sdfOld.toPattern()); try { return sdfOld.parse(source); } catch (ParseException exception) { LOGGER.warn("Failed to parse date [{}] using format [{}]. Defaulting to the current date.", source, sdfOld.toPattern()); return new Date(); } } }  static Date parseDate(String source); static String serializeDate(Object date); @Override Object read(XMLStreamReader reader); @Override void write(XMLStreamWriter writer, Object value); }
DateXarObjectPropertySerializer implements XarObjectPropertySerializer { public static Date parseDate(String source) { SimpleDateFormat format = new SimpleDateFormat(DEFAULT_FORMAT); try { return format.parse(source); } catch (ParseException e) { SimpleDateFormat sdfOld = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy", Locale.US); LOGGER.warn("Failed to parse date [{}] using format [{}]. Trying again with format [{}].", source, DEFAULT_FORMAT, sdfOld.toPattern()); try { return sdfOld.parse(source); } catch (ParseException exception) { LOGGER.warn("Failed to parse date [{}] using format [{}]. Defaulting to the current date.", source, sdfOld.toPattern()); return new Date(); } } }  static Date parseDate(String source); static String serializeDate(Object date); @Override Object read(XMLStreamReader reader); @Override void write(XMLStreamWriter writer, Object value); static final String DEFAULT_FORMAT; }