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:33 UTC

[commons-lang] branch master updated (c267e39 -> ff1209f)

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

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


    from c267e39  Reuse constant TimeZones.GMT_ID.
     new eea85f2  Add and use TimeZones.GMT.
     new ff1209f  Inline duplicate constants.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                                   |  1 +
 .../java/org/apache/commons/lang3/time/TimeZones.java     | 11 ++++++++++-
 .../org/apache/commons/lang3/time/FastDateParserTest.java | 15 +++++++--------
 .../apache/commons/lang3/time/FastDatePrinterTest.java    |  9 ++++-----
 .../commons/lang3/time/Java15BugFastDateParserTest.java   |  4 ++--
 5 files changed, 24 insertions(+), 16 deletions(-)

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

Posted by gg...@apache.org.
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();

[commons-lang] 02/02: Inline duplicate constants.

Posted by gg...@apache.org.
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 ff1209f00f4e3c0f2d55dc24ccf20da625ca4e61
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Aug 31 10:57:30 2021 -0400

    Inline duplicate constants.
---
 .../org/apache/commons/lang3/time/FastDateParserTest.java | 15 +++++++--------
 .../apache/commons/lang3/time/FastDatePrinterTest.java    |  3 +--
 .../commons/lang3/time/Java15BugFastDateParserTest.java   |  4 ++--
 3 files changed, 10 insertions(+), 12 deletions(-)

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 d7752a5..e548d2c 100644
--- a/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
@@ -54,7 +54,7 @@ import org.junit.jupiter.params.provider.MethodSource;
 public class FastDateParserTest {
 
     private enum Expected1806 {
-        India(INDIA, "+05", "+0530", "+05:30", true), Greenwich(GMT, "Z", "Z", "Z", false),
+        India(INDIA, "+05", "+0530", "+05:30", true), Greenwich(TimeZones.GMT, "Z", "Z", "Z", false),
         NewYork(NEW_YORK, "-05", "-0500", "-05:00", false);
 
         final TimeZone zone;
@@ -90,7 +90,6 @@ 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 = TimeZones.GMT;
     private static final TimeZone INDIA = TimeZone.getTimeZone("Asia/Calcutta");
 
     private static final Locale SWEDEN = new Locale("sv", "SE");
@@ -320,7 +319,7 @@ public class FastDateParserTest {
     @Test
     public void testJpLocales() throws ParseException {
 
-        final Calendar cal = Calendar.getInstance(GMT);
+        final Calendar cal = Calendar.getInstance(TimeZones.GMT);
         cal.clear();
         cal.set(2003, Calendar.FEBRUARY, 10);
         cal.set(Calendar.ERA, GregorianCalendar.BC);
@@ -376,11 +375,11 @@ public class FastDateParserTest {
     @ParameterizedTest
     @MethodSource(DATE_PARSER_PARAMETERS)
     public void testLang1380(final TriFunction<String, TimeZone, Locale, DateParser> dpProvider) throws ParseException {
-        final Calendar expected = Calendar.getInstance(GMT, Locale.FRANCE);
+        final Calendar expected = Calendar.getInstance(TimeZones.GMT, Locale.FRANCE);
         expected.clear();
         expected.set(2014, Calendar.APRIL, 14);
 
-        final DateParser fdp = getInstance(dpProvider, "dd MMM yyyy", GMT, Locale.FRANCE);
+        final DateParser fdp = getInstance(dpProvider, "dd MMM yyyy", TimeZones.GMT, Locale.FRANCE);
         assertEquals(expected.getTime(), fdp.parse("14 avril 2014"));
         assertEquals(expected.getTime(), fdp.parse("14 avr. 2014"));
         assertEquals(expected.getTime(), fdp.parse("14 avr 2014"));
@@ -400,7 +399,7 @@ public class FastDateParserTest {
 
     @Test
     public void testLang538() throws ParseException {
-        final DateParser parser = getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", GMT);
+        final DateParser parser = getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", TimeZones.GMT);
 
         final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT-8"));
         cal.clear();
@@ -514,7 +513,7 @@ public class FastDateParserTest {
     public void testParses() throws Exception {
         for (final String format : new String[] {LONG_FORMAT, SHORT_FORMAT}) {
             for (final Locale locale : Locale.getAvailableLocales()) {
-                for (final TimeZone timeZone : new TimeZone[] {NEW_YORK, REYKJAVIK, GMT}) {
+                for (final TimeZone timeZone : new TimeZone[] {NEW_YORK, REYKJAVIK, TimeZones.GMT}) {
                     for (final int year : new int[] {2003, 1940, 1868, 1867, 1, -1, -1940}) {
                         final Calendar cal = getEraStart(year, timeZone, locale);
                         final Date centuryStart = cal.getTime();
@@ -691,7 +690,7 @@ public class FastDateParserTest {
         for (final Locale locale : Locale.getAvailableLocales()) {
             final FastDateParser fdp = new FastDateParser("yyyy/MM/dd z", TimeZone.getDefault(), locale);
 
-            for (final TimeZone timeZone : new TimeZone[] {NEW_YORK, REYKJAVIK, GMT}) {
+            for (final TimeZone timeZone : new TimeZone[] {NEW_YORK, REYKJAVIK, TimeZones.GMT}) {
                 final Calendar cal = Calendar.getInstance(timeZone, locale);
                 cal.clear();
                 cal.set(Calendar.YEAR, 2000);
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 6ef333a..772973e 100644
--- a/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTest.java
@@ -43,7 +43,7 @@ import org.junitpioneer.jupiter.DefaultTimeZone;
 public class FastDatePrinterTest {
 
     private enum Expected1806 {
-        India(INDIA, "+05", "+0530", "+05:30"), Greenwich(GMT, "Z", "Z", "Z"), NewYork(
+        India(INDIA, "+05", "+0530", "+05:30"), Greenwich(TimeZones.GMT, "Z", "Z", "Z"), NewYork(
                 NEW_YORK, "-05", "-0500", "-05:00");
 
         final TimeZone zone;
@@ -60,7 +60,6 @@ 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 = 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/Java15BugFastDateParserTest.java b/src/test/java/org/apache/commons/lang3/time/Java15BugFastDateParserTest.java
index 265ca00..9ac105a 100644
--- a/src/test/java/org/apache/commons/lang3/time/Java15BugFastDateParserTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/Java15BugFastDateParserTest.java
@@ -67,7 +67,7 @@ public class Java15BugFastDateParserTest {
     private void testLocales(final TriFunction<String, TimeZone, Locale, DateParser> dbProvider, final String format,
         final boolean eraBC) throws Exception {
 
-        final Calendar cal = Calendar.getInstance(FastDateParserTest.GMT);
+        final Calendar cal = Calendar.getInstance(TimeZones.GMT);
         cal.clear();
         cal.set(2003, Calendar.FEBRUARY, 10);
         if (eraBC) {
@@ -144,7 +144,7 @@ public class Java15BugFastDateParserTest {
     }
 
     private void testSingleLocale(final Locale locale) throws ParseException {
-        final Calendar cal = Calendar.getInstance(FastDateParserTest.GMT);
+        final Calendar cal = Calendar.getInstance(TimeZones.GMT);
         cal.clear();
         cal.set(2003, Calendar.FEBRUARY, 10);
         final SimpleDateFormat sdf = new SimpleDateFormat(FastDateParserTest.LONG_FORMAT, locale);