Skip to content

Commit

Permalink
add compatibility for java <= 19 DateFormat to default DateTypeAdapte…
Browse files Browse the repository at this point in the history
…r, for ability read new format
  • Loading branch information
turchenkoalex committed Jun 7, 2024
1 parent 9b76785 commit de8d40d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,13 @@ public class PreJava20DateFormatProvider {
public static DateFormat getUSDateFormat() {
return new SimpleDateFormat("MMM d, y, h:mm:ss a", Locale.US);
}

/**
* Compatibility fix for old Javas runtime, if date was written by JDK 20 or greater
* @return Returns the same DateFormat as {@code DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.US)}
* in Java 20 or upper.
*/
public static DateFormat getNewUSDateFormat() {
return new SimpleDateFormat("MMM d, y, h:mm:ss a", Locale.US);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public DateTypeAdapter() {
}
if (JavaVersion.isJava20OrLater()) {
dateFormats.add(PreJava20DateFormatProvider.getUSDateFormat());
} else {
dateFormats.add(PreJava20DateFormatProvider.getNewUSDateFormat());
}
}

Expand Down

0 comments on commit de8d40d

Please sign in to comment.