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 86b6fd600..f2d986995 100644 --- a/src/main/java/org/apache/commons/lang3/time/CalendarUtils.java +++ b/src/main/java/org/apache/commons/lang3/time/CalendarUtils.java @@ -77,6 +77,16 @@ public class CalendarUtils { return calendar.get(Calendar.DAY_OF_MONTH); } + /** + * Gets the current day of year. + * + * @return the current day of year. + * @since 3.13.0 + */ + public int getDayOfYear() { + return calendar.get(Calendar.DAY_OF_YEAR); + } + /** * Gets the current month. * 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 53ac724b1..79685f7a3 100644 --- a/src/test/java/org/apache/commons/lang3/time/CalendarUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/time/CalendarUtilsTest.java @@ -32,6 +32,11 @@ public class CalendarUtilsTest extends AbstractLangTest { assertEquals(Calendar.getInstance().get(Calendar.DAY_OF_MONTH), CalendarUtils.INSTANCE.getDayOfMonth()); } + @Test + public void testGetDayOfYear() { + assertEquals(Calendar.getInstance().get(Calendar.DAY_OF_YEAR), CalendarUtils.INSTANCE.getDayOfYear()); + } + @Test public void testGetMonth() { assertEquals(Calendar.getInstance().get(Calendar.MONTH), CalendarUtils.INSTANCE.getMonth());