From eea85f25e583b379afe5ba506a1519cc3704186f Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Tue, 31 Aug 2021 10:51:22 -0400 Subject: [PATCH] Add and use TimeZones.GMT. --- src/changes/changes.xml | 1 + .../java/org/apache/commons/lang3/time/TimeZones.java | 11 ++++++++++- .../apache/commons/lang3/time/FastDateParserTest.java | 2 +- .../commons/lang3/time/FastDatePrinterTest.java | 8 ++++---- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 7bcccd9fa..ea9ea39e0 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -80,6 +80,7 @@ The type attribute can be add,update,fix,remove. Add UncheckedExecutionException. Add UncheckedTimeoutException. Add UncheckedInterruptedException. + Add TimeZones.GMT. Bump spotbugs-maven-plugin from 4.2.0 to 4.2.3 #735. Bump Bump actions/cache from v2.1.4 to v2.1.6 #742, #752, #764. diff --git a/src/main/java/org/apache/commons/lang3/time/TimeZones.java b/src/main/java/org/apache/commons/lang3/time/TimeZones.java index 5a7569042..4f7a00915 100644 --- a/src/main/java/org/apache/commons/lang3/time/TimeZones.java +++ b/src/main/java/org/apache/commons/lang3/time/TimeZones.java @@ -17,6 +17,8 @@ package org.apache.commons.lang3.time; +import java.util.TimeZone; + /** * Helps to deal with {@link java.util.TimeZone}s. * @@ -24,7 +26,7 @@ package org.apache.commons.lang3.time; */ public class TimeZones { - // do not instantiate + // Do not instantiate. private TimeZones() { } @@ -32,4 +34,11 @@ public class TimeZones { * A public version of {@link java.util.TimeZone}'s package private {@code GMT_ID} field. */ public static final String GMT_ID = "GMT"; + + /** + * The GMT time zone. + * + * @since 3.13.0 + */ + public static final TimeZone GMT = TimeZone.getTimeZone(GMT_ID); } diff --git a/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java b/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java index f37b60a8b..d7752a58e 100644 --- a/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java +++ b/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java @@ -90,7 +90,7 @@ public class FastDateParserTest { private static final TimeZone REYKJAVIK = TimeZone.getTimeZone("Atlantic/Reykjavik"); private static final TimeZone NEW_YORK = TimeZone.getTimeZone("America/New_York"); - static final TimeZone GMT = TimeZone.getTimeZone(TimeZones.GMT_ID); + static final TimeZone GMT = TimeZones.GMT; private static final TimeZone INDIA = TimeZone.getTimeZone("Asia/Calcutta"); private static final Locale SWEDEN = new Locale("sv", "SE"); diff --git a/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTest.java b/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTest.java index c8837d2d1..6ef333a5e 100644 --- a/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTest.java +++ b/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTest.java @@ -60,7 +60,7 @@ public class FastDatePrinterTest { } private static final String YYYY_MM_DD = "yyyy/MM/dd"; private static final TimeZone NEW_YORK = TimeZone.getTimeZone("America/New_York"); - private static final TimeZone GMT = TimeZone.getTimeZone(TimeZones.GMT_ID); + private static final TimeZone GMT = TimeZones.GMT; private static final TimeZone INDIA = TimeZone.getTimeZone("Asia/Calcutta"); private static final Locale SWEDEN = new Locale("sv", "SE"); @@ -126,7 +126,7 @@ public class FastDatePrinterTest { @Test public void testAppendableOptions() { - final DatePrinter format = getInstance("yyyy-MM-dd HH:mm:ss.SSS Z", TimeZone.getTimeZone(TimeZones.GMT_ID)); + final DatePrinter format = getInstance("yyyy-MM-dd HH:mm:ss.SSS Z", TimeZones.GMT); final Calendar calendar = Calendar.getInstance(); final StringBuilder sb = new StringBuilder(); final String expected = format.format(calendar, sb).toString(); @@ -262,7 +262,7 @@ public class FastDatePrinterTest { cal.clear(); cal.set(2009, Calendar.OCTOBER, 16, 8, 42, 16); - final DatePrinter format = getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", TimeZone.getTimeZone(TimeZones.GMT_ID)); + final DatePrinter format = getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", TimeZones.GMT); assertEquals("2009-10-16T16:42:16.000Z", format.format(cal.getTime()), "dateTime"); assertEquals("2009-10-16T16:42:16.000Z", format.format(cal), "dateTime"); } @@ -387,7 +387,7 @@ public class FastDatePrinterTest { @SuppressWarnings("deprecation") @Test public void testStringBufferOptions() { - final DatePrinter format = getInstance("yyyy-MM-dd HH:mm:ss.SSS Z", TimeZone.getTimeZone(TimeZones.GMT_ID)); + final DatePrinter format = getInstance("yyyy-MM-dd HH:mm:ss.SSS Z", TimeZones.GMT); final Calendar calendar = Calendar.getInstance(); final StringBuffer sb = new StringBuffer(); final String expected = format.format(calendar, sb, new FieldPosition(0)).toString();