Skip to content

TimeConverter used to use the SimpleDateFormat #617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions core/src/main/java/cucumber/runtime/xstream/TimeConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

abstract class TimeConverter<T> extends ConverterWithFormat<T> {
private final List<DateFormat> formats = new ArrayList<DateFormat>();
private SimpleDateFormat onlyFormat;
private String format;

TimeConverter(Locale locale, Class[] convertibleTypes) {
super(convertibleTypes);
Expand All @@ -37,7 +37,14 @@ void add(DateFormat dateFormat) {
}

public List<? extends Format> getFormats() {
return onlyFormat == null ? formats : asList(onlyFormat);
return format == null ? formats : asList(getOnlyFormat());
}

private Format getOnlyFormat() {
DateFormat dateFormat = new SimpleDateFormat(format, getLocale());
dateFormat.setLenient(false);

return dateFormat;
}

@Override
Expand All @@ -51,14 +58,14 @@ public String toString(Object obj) {
@Override
public void setParameterInfoAndLocale(ParameterInfo parameterInfo, Locale locale) {
super.setParameterInfoAndLocale(parameterInfo, locale);

if (parameterInfo.getFormat() != null) {
onlyFormat = new SimpleDateFormat(parameterInfo.getFormat(), locale);
onlyFormat.setLenient(false);
format = parameterInfo.getFormat();
}
}

public void removeOnlyFormat() {
onlyFormat = null;
format = null;
}

public static List<Class> getTimeClasses() {
Expand Down