#1518·CoreNLP

SUTime: duration arithmetic emits TIMEX values that are not valid ISO 8601

Author: AngledLuffaCreated Sep 25, 2026Updated Sep 25, 2026

SUTime: duration arithmetic emits TIMEX values that are not valid ISO 8601

Summary

SUTime.Duration.subtract and a negative multiplyBy leave the sign on an individual component, so the resulting TIMEX value has a minus sign in the middle of the duration. ISO 8601 puts the sign in front of the whole duration, if it allows one at all.

Reproduction

java
SUTime.YEAR.subtract(SUTime.MONTH).getTimexValue()   ->  P1Y-1M
SUTime.WEEK.subtract(SUTime.DAY).getTimexValue()     ->  P1W-1D
SUTime.HOUR.subtract(SUTime.MINUTE).getTimexValue()  ->  PT1H-1M
SUTime.DAY.multiplyBy(-2).getTimexValue()            ->  P-2D
SUTime.MONTH.multiplyBy(-1).getTimexValue()          ->  P-1M

P1Y-1M is eleven months and should render as P11M. P-2D should be -P2D, or be rejected, depending on whether negative durations are meant to be expressible at all.

Addition is fine, because nothing needs normalising:

java
SUTime.YEAR.add(SUTime.MONTH).getTimexValue()        ->  P1Y1M

One related oddity: multiplying by zero gives PT0S rather than P0D, so a zero-length duration loses the unit it was measured in. That is at least valid ISO 8601.

Cause

The value comes from the underlying period's own rendering, which prints each field independently with its own sign. Nothing normalises the period first, so P1Y minus P1M stays as a years field of 1 and a months field of -1 rather than becoming 11 months.

A normalizedStandard() on the period before rendering would fix the subtraction cases. The negative-multiplier cases need a decision rather than a normalisation, since a duration of minus two days is not something ISO 8601 expresses in a single value.

Reach

Neither path reaches TIMEX output today.

Duration.subtract has no callers in CoreNLP at all, so P1Y-1M and its siblings are reachable only through the public API.

multiplyBy with a negative argument is used internally — SUTime.YESTERDAY is DAY.multiplyBy(-1), and SUTime.java:525 and :529 use per.multiplyBy(-1) to build offsets — but the results are consumed as offsets and resolved into dates rather than emitted as durations. Checking a 2075-sentence corpus and the obvious phrasings:

"It happened yesterday."            -> 2010-02-16   DATE
"It happened two days ago."         -> 2010-02-15   DATE
"It lasted two days."               -> P2D          DURATION

No negative or unnormalised duration appears anywhere in that corpus.

So this is latent rather than user-visible, and a fix is low-risk: no rule, annotator or test output changes.

Suggested fix

Normalise the period before rendering, which resolves the subtraction cases. For the negative cases, decide whether a negative duration should render with a leading sign (-P2D), be normalised away by whatever consumes it, or be rejected at construction.

Worth doing alongside a decision on multiplyBy(0), which currently discards the unit.