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
The following commit(s) were added to refs/heads/master by this push:
new 6e3e6e246 Add CalendarUtils.getInstance()
6e3e6e246 is described below
commit 6e3e6e2467ecad07099c2908df543f191a6007e1
Author: Gary Gregory <[email protected]>
AuthorDate: Sat Aug 5 09:16:49 2023 -0400
Add CalendarUtils.getInstance()
Test should compare apples to apples
---
src/changes/changes.xml | 1 +
.../org/apache/commons/lang3/time/CalendarUtils.java | 18 ++++++++++++++++--
.../apache/commons/lang3/time/CalendarUtilsTest.java | 7 +++----
3 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f3c3a141c..13ff15f33 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -55,6 +55,7 @@ The <action> type attribute can be add,update,fix,remove.
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Rob Spoor,
Gary Gregory">Add Functions#function(Function).</action>
<action type="add" dev="ggregory" due-to="Rob Spoor,
Gary Gregory">Add FailableFunction#function(FailableFunction).</action>
+ <action type="add" dev="ggregory" due-to="Gary
Gregory">Add CalendarUtils.getInstance().</action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Gary
Gregory">Bump commons-parent from 58 to 59.</action>
</release>
diff --git a/src/main/java/org/apache/commons/lang3/time/CalendarUtils.java
b/src/main/java/org/apache/commons/lang3/time/CalendarUtils.java
index f2d986995..eda1dfb57 100644
--- a/src/main/java/org/apache/commons/lang3/time/CalendarUtils.java
+++ b/src/main/java/org/apache/commons/lang3/time/CalendarUtils.java
@@ -19,6 +19,7 @@ package org.apache.commons.lang3.time;
import java.util.Calendar;
import java.util.Locale;
+import java.util.Locale.Category;
import java.util.Map;
import java.util.Objects;
@@ -30,9 +31,22 @@ import java.util.Objects;
public class CalendarUtils {
/**
- * The singleton instance for {@link Calendar#getInstance()}.
+ * The singleton instance for {@link Calendar#getInstance()}. The instance
is created when the class is initialized and is based on the current time in the
+ * default time zone with the default {@link Category#FORMAT} locale.
+ *
+ * @see CalendarUtils#getInstance()
*/
- public static final CalendarUtils INSTANCE = new
CalendarUtils(Calendar.getInstance());
+ public static final CalendarUtils INSTANCE = getInstance();
+
+ /**
+ * Creates a new instance based on the current time in the default time
zone with the default {@link Category#FORMAT} locale.
+ *
+ * @return a new instance.
+ * @since 3.14.0
+ */
+ public static CalendarUtils getInstance() {
+ return new CalendarUtils(Calendar.getInstance());
+ }
/**
* Gets a CalendarUtils using the default time zone and specified locale.
The <code>CalendarUtils</code> returned is based on the current time in the
diff --git a/src/test/java/org/apache/commons/lang3/time/CalendarUtilsTest.java
b/src/test/java/org/apache/commons/lang3/time/CalendarUtilsTest.java
index 79685f7a3..1faea43f6 100644
--- a/src/test/java/org/apache/commons/lang3/time/CalendarUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/CalendarUtilsTest.java
@@ -29,17 +29,17 @@ public class CalendarUtilsTest extends AbstractLangTest {
@Test
public void testGetDayOfMonth() {
- assertEquals(Calendar.getInstance().get(Calendar.DAY_OF_MONTH),
CalendarUtils.INSTANCE.getDayOfMonth());
+ assertEquals(Calendar.getInstance().get(Calendar.DAY_OF_MONTH),
CalendarUtils.getInstance().getDayOfMonth());
}
@Test
public void testGetDayOfYear() {
- assertEquals(Calendar.getInstance().get(Calendar.DAY_OF_YEAR),
CalendarUtils.INSTANCE.getDayOfYear());
+ assertEquals(Calendar.getInstance().get(Calendar.DAY_OF_YEAR),
CalendarUtils.getInstance().getDayOfYear());
}
@Test
public void testGetMonth() {
- assertEquals(Calendar.getInstance().get(Calendar.MONTH),
CalendarUtils.INSTANCE.getMonth());
+ assertEquals(Calendar.getInstance().get(Calendar.MONTH),
CalendarUtils.getInstance().getMonth());
}
@Test
@@ -83,5 +83,4 @@ public class CalendarUtilsTest extends AbstractLangTest {
assertEquals(Calendar.getInstance().get(Calendar.YEAR),
CalendarUtils.INSTANCE.getYear());
}
-
}