The problem is the order the operations are evaluated in:
-1.day
is equivalent to -(1.day)
, or (1.day).negative()
To solve this, you can apply parentheses to evaluate the minus operator first:
(-1).day
Another solution is to add a negative()
method to the Duration
class.
Duration.metaClass.negative = { ->
new Duration(-delegate.days,
-delegate.hours,
-delegate.minutes,
-delegate.seconds,
-delegate.millis)
}