@@ -473,6 +473,53 @@ void testFormatPeriod() {
473473 assertEquals ("helloworld" , DurationFormatUtils .formatPeriod (time1970 , time , "'hello''world'" ));
474474 }
475475
476+ /** Covers negative-day borrowing across month boundary */
477+ @ Test
478+ void testFormatPeriodISONegativeDaysBorrowAcrossMonth () {
479+ final TimeZone tz = TimeZones .getTimeZone ("GMT-3" );
480+
481+ final Calendar start = Calendar .getInstance (tz );
482+ start .set (2020 , Calendar .JANUARY , 31 , 0 , 0 , 0 );
483+ start .set (Calendar .MILLISECOND , 0 );
484+
485+ final Calendar end = Calendar .getInstance (tz );
486+ end .set (2020 , Calendar .FEBRUARY , 1 , 0 , 0 , 0 );
487+ end .set (Calendar .MILLISECOND , 0 );
488+
489+ final String result = DurationFormatUtils .formatPeriod (
490+ start .getTimeInMillis (),
491+ end .getTimeInMillis (),
492+ DurationFormatUtils .ISO_EXTENDED_FORMAT_PATTERN ,
493+ false ,
494+ tz
495+ );
496+
497+ assertEquals ("P0Y0M1DT0H0M0.000S" , result );
498+ }
499+
500+ @ Test
501+ void testFormatPeriodISONegativeDaysLeapYear () {
502+ final TimeZone tz = TimeZones .getTimeZone ("GMT-3" );
503+
504+ final Calendar start = Calendar .getInstance (tz );
505+ start .set (2020 , Calendar .FEBRUARY , 29 , 0 , 0 , 0 );
506+ start .set (Calendar .MILLISECOND , 0 );
507+
508+ final Calendar end = Calendar .getInstance (tz );
509+ end .set (2020 , Calendar .MARCH , 1 , 0 , 0 , 0 );
510+ end .set (Calendar .MILLISECOND , 0 );
511+
512+ final String result = DurationFormatUtils .formatPeriod (
513+ start .getTimeInMillis (),
514+ end .getTimeInMillis (),
515+ DurationFormatUtils .ISO_EXTENDED_FORMAT_PATTERN ,
516+ false ,
517+ tz
518+ );
519+
520+ assertEquals ("P0Y0M1DT0H0M0.000S" , result );
521+ }
522+
476523 @ Test
477524 void testFormatPeriodeStartGreaterEnd () {
478525 assertIllegalArgumentException (() -> DurationFormatUtils .formatPeriod (5000 , 2500 , "yy/MM" ));
@@ -505,8 +552,6 @@ void testFormatPeriodISO() {
505552 assertEquals ("P1Y1M2DT10H30M0.000S" , text );
506553 // want a way to say 'don't print the seconds in format()' or other fields for that matter:
507554 // assertEquals("P1Y2M3DT10H30M", text);
508- //
509- // TODO Jacoco shows missing coverage for internal negative days
510555 }
511556
512557 @ Test
0 commit comments