Skip to content
Permalink
Browse files

Merge pull request #333 from vgionco/develop

Fix DURATION parsing on negative 'W' durations.
  • Loading branch information...
benfortuna committed Jun 7, 2019
2 parents 93f4412 + 6a0ea2f commit 128c01ac6bfd61b24c689220cbb8c09516cbfb92
@@ -115,7 +115,7 @@ private String durationToString(Duration duration) {

public static TemporalAmountAdapter parse(String value) {
TemporalAmount retVal = null;
if (value.matches("P.*(W|D)$")) {
if (value.matches("([+-])?P.*(W|D)")) {
retVal = java.time.Period.parse(value);
} else {
retVal = java.time.Duration.parse(value);
@@ -148,4 +148,15 @@ class TemporalAmountAdapterTest extends Specification {
adapter1.hashCode() == adapter2.hashCode()
}

def 'week period parsing and values'() {
given: 'a one week amount adapter'
TemporalAmountAdapter adapter1 = TemporalAmountAdapter.parse('P1W')

and: 'a negative one week identical period'
TemporalAmountAdapter adapter2 = TemporalAmountAdapter.parse('-P1W')

expect: 'same duration, except for the sign'
adapter1.duration == -adapter2.duration
}

}

0 comments on commit 128c01a

Please sign in to comment.
You can’t perform that action at this time.