You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/08/31 14:57:34 UTC

[commons-lang] 01/02: Add and use TimeZones.GMT.

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git

commit eea85f25e583b379afe5ba506a1519cc3704186f
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Aug 31 10:51:22 2021 -0400

    Add and use TimeZones.GMT.
---
 src/changes/changes.xml                                       |  1 +
 src/main/java/org/apache/commons/lang3/time/TimeZones.java    | 11 ++++++++++-
 .../org/apache/commons/lang3/time/FastDateParserTest.java     |  2 +-
 .../org/apache/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 7bcccd9..ea9ea39 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -80,6 +80,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add UncheckedExecutionException.</action>
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add UncheckedTimeoutException.</action>
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add UncheckedInterruptedException.</action>
+    <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add TimeZones.GMT.</action>
     <!-- UPDATE -->
     <action                   type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump spotbugs-maven-plugin from 4.2.0 to 4.2.3 #735.</action>
     <action                   type="update" dev="ggregory" due-to="Dependabot, XenoAmess">Bump Bump actions/cache from v2.1.4 to v2.1.6 #742, #752, #764.</action>
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 5a75690..4f7a009 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 f37b60a..d7752a5 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 c8837d2..6ef333a 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();