1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-27 06:42:05 +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() { private DateUtil() {
} }
public static SimpleDateFormat UTC_PARSER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
static { public static SimpleDateFormat getParser() {
UTC_PARSER.setTimeZone(TimeZone.getTimeZone("UTC")); 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) { public static Date parseUTCDate(String dateString) {
try { try {
return UTC_PARSER.parse(dateString); return getParser().parse(dateString);
} catch (ParseException e) { } catch (ParseException e) {
return null; return null;
} }
@ -51,7 +53,7 @@ public final class DateUtil {
* @return timestamp * @return timestamp
*/ */
public static String formatUTCDate(Date date) { public static String formatUTCDate(Date date) {
return UTC_PARSER.format(date); return getParser().format(date);
} }
/** /**