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 da6d3371c Add test coverage for negative-day adjustment in
DurationFormatUtils (#1596)
da6d3371c is described below
commit da6d3371c053be80e6d57c969105fcca9999b0af
Author: TK_ENDO <[email protected]>
AuthorDate: Fri Feb 13 21:09:20 2026 +0800
Add test coverage for negative-day adjustment in DurationFormatUtils (#1596)
Adds unit tests covering month-boundary and leap-year cases that
trigger the internal negative-days borrowing logic in
DurationFormatUtils.formatPeriod.
Removes obsolete TODO about missing JaCoCo coverage.
---
.../lang3/time/DurationFormatUtilsTest.java | 50 +++++++++++++++++++++-
1 file changed, 48 insertions(+), 2 deletions(-)
diff --git
a/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java
b/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java
index b19911e6a..13b42602a 100644
--- a/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java
@@ -473,6 +473,54 @@ void testFormatPeriod() {
assertEquals("helloworld", DurationFormatUtils.formatPeriod(time1970,
time, "'hello''world'"));
}
+ @Test
+ void testFormatPeriodISOAcrossMonths() {
+ final TimeZone tz = TimeZones.getTimeZone("GMT-3");
+
+ // Verifies period formatting across a month boundary (Jan 31 to Feb 1)
+ final Calendar start = Calendar.getInstance(tz);
+ start.clear();
+ start.set(2020, Calendar.JANUARY, 31);
+
+ final Calendar end = Calendar.getInstance(tz);
+ end.clear();
+ end.set(2020, Calendar.FEBRUARY, 1);
+
+ final String result = DurationFormatUtils.formatPeriod(
+ start.getTimeInMillis(),
+ end.getTimeInMillis(),
+ DurationFormatUtils.ISO_EXTENDED_FORMAT_PATTERN,
+ false,
+ tz
+ );
+
+ assertEquals("P0Y0M1DT0H0M0.000S", result);
+ }
+
+ @Test
+ void testFormatPeriodISOLeapYearBoundary() {
+ final TimeZone tz = TimeZones.getTimeZone("GMT-3");
+
+ // Verifies period formatting across a leap-year boundary (Feb 29 to
Mar 1)
+ final Calendar start = Calendar.getInstance(tz);
+ start.clear();
+ start.set(2020, Calendar.FEBRUARY, 29);
+
+ final Calendar end = Calendar.getInstance(tz);
+ end.clear();
+ end.set(2020, Calendar.MARCH, 1);
+
+ final String result = DurationFormatUtils.formatPeriod(
+ start.getTimeInMillis(),
+ end.getTimeInMillis(),
+ DurationFormatUtils.ISO_EXTENDED_FORMAT_PATTERN,
+ false,
+ tz
+ );
+
+ assertEquals("P0Y0M1DT0H0M0.000S", result);
+ }
+
@Test
void testFormatPeriodeStartGreaterEnd() {
assertIllegalArgumentException(() ->
DurationFormatUtils.formatPeriod(5000, 2500, "yy/MM"));
@@ -505,8 +553,6 @@ void testFormatPeriodISO() {
assertEquals("P1Y1M2DT10H30M0.000S", text);
// want a way to say 'don't print the seconds in format()' or other
fields for that matter:
// assertEquals("P1Y2M3DT10H30M", text);
- //
- // TODO Jacoco shows missing coverage for internal negative days
}
@Test