@Test public void should_returnDate_when_stringRepresentsADate() { String dateStr = "1970-01-01"; Date date = provider.toDate(dateStr); assertThat(date).hasTime(0); }
public Date toDate(Object value) { if (value instanceof String) { return parse((String) value); } if (value instanceof Date) { return (Date)value; } if (value instanceof Long) { return new Date((long)value); } throw new DateTimeException(MessageFormat.format("Error while parsing date. Type: {0}, value: {1}", value.getClass().getName(), value)); }
DateFormatterProvider { public Date toDate(Object value) { if (value instanceof String) { return parse((String) value); } if (value instanceof Date) { return (Date)value; } if (value instanceof Long) { return new Date((long)value); } throw new DateTimeException(MessageFormat.format("Error while parsing date. Type: {0}, value: {1}", value.getClass().getName(), value)); } }
DateFormatterProvider { public Date toDate(Object value) { if (value instanceof String) { return parse((String) value); } if (value instanceof Date) { return (Date)value; } if (value instanceof Long) { return new Date((long)value); } throw new DateTimeException(MessageFormat.format("Error while parsing date. Type: {0}, value: {1}", value.getClass().getName(), value)); } DateFormatterProvider(String dateFormatPattern); }
DateFormatterProvider { public Date toDate(Object value) { if (value instanceof String) { return parse((String) value); } if (value instanceof Date) { return (Date)value; } if (value instanceof Long) { return new Date((long)value); } throw new DateTimeException(MessageFormat.format("Error while parsing date. Type: {0}, value: {1}", value.getClass().getName(), value)); } DateFormatterProvider(String dateFormatPattern); ZoneId getZoneId(); String getDateFormatPattern(); void setDateFormatPattern(String dateFormatPattern); Date parse(String value); Date toDate(Object value); }
DateFormatterProvider { public Date toDate(Object value) { if (value instanceof String) { return parse((String) value); } if (value instanceof Date) { return (Date)value; } if (value instanceof Long) { return new Date((long)value); } throw new DateTimeException(MessageFormat.format("Error while parsing date. Type: {0}, value: {1}", value.getClass().getName(), value)); } DateFormatterProvider(String dateFormatPattern); ZoneId getZoneId(); String getDateFormatPattern(); void setDateFormatPattern(String dateFormatPattern); Date parse(String value); Date toDate(Object value);  }