Skip to content

Commit

Permalink
Fix minutes/seconds parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Jun 28, 2020
1 parent e6a002f commit eea4a6c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Expand Up @@ -92,11 +92,17 @@ private String durationToString(Duration duration) {
if (hours > 0) {
if (seconds > 0) {
retVal = String.format("P%dDT%dH%dM%dS", days, hours, minutes, seconds);
} else if (minutes > 0) {
retVal = String.format("P%dDT%dH%dM", days, hours, minutes);
} else {
retVal = String.format("P%dDT%dH", days, hours);
}
} else if (minutes > 0) {
retVal = String.format("P%dDT%dM", days, minutes);
if (seconds > 0) {
retVal = String.format("P%dDT%dM%dS", days, minutes, seconds);
} else {
retVal = String.format("P%dDT%dM", days, minutes);
}
} else if (seconds > 0) {
retVal = String.format("P%dDT%dS", days, seconds);
}
Expand Down
Expand Up @@ -181,4 +181,7 @@ class TemporalAmountAdapterTest extends Specification {
adapter1.duration == -adapter2.duration
}

def 'testTemporalAmountAdapter_durationToString_DropsMinutes'() {
expect: "P1DT1H4M" == TemporalAmountAdapter.parse("P1DT1H4M") as String
}
}

0 comments on commit eea4a6c

Please sign in to comment.