1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-23 04:42:06 +01:00

Make DateUtil thread-safe

This commit is contained in:
Paul Schaub 2021-08-15 15:33:08 +02:00
parent bb27fddc89
commit ccc62e090c

View file

@ -25,9 +25,11 @@ public final class DateUtil {
private DateUtil() {
}
public static SimpleDateFormat UTC_PARSER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
static {
UTC_PARSER.setTimeZone(TimeZone.getTimeZone("UTC"));
public static SimpleDateFormat getParser() {
SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
parser.setTimeZone(TimeZone.getTimeZone("UTC"));
return parser;
}
/**
@ -38,7 +40,7 @@ public final class DateUtil {
*/
public static Date parseUTCDate(String dateString) {
try {
return UTC_PARSER.parse(dateString);
return getParser().parse(dateString);
} catch (ParseException e) {
return null;
}
@ -51,7 +53,7 @@ public final class DateUtil {
* @return timestamp
*/
public static String formatUTCDate(Date date) {
return UTC_PARSER.format(date);
return getParser().format(date);
}
/**