Relationships
#3714 CEL duration arithmetic is off by a second when a duration has negative nanos (cel-js 7.6.1)
Opened by zack · 10/21/2026· Shipped 10/22/2026
Description
cel-js 7.6.1 (npm:@marcbachmann/cel-js) gives wrong results when adding or subtracting durations where one operand was parsed from a negative literal. Parsing stores a negative duration with both seconds and nanos negative (duration('-1213479513ns') holds seconds -1, nanos -213479513), but Duration.addDuration / subtractDuration assume nanos is non-negative and borrow a second twice.
Found while fixing swamp-club#3713.
Steps to reproduce
With a bare cel-js Environment:
- duration('-1.5s') + duration('-0.6s') == duration('-2.1s') evaluates to false
- duration('-1213479513ns') - duration('554786520488ns') holds seconds -557, nanos -1 (-557.000000001s); the right answer is -556.000000001s
Duration equality also compares the stored seconds and nanos fields, so two equal durations built different ways compare unequal: duration('0ns') - duration('1ns') holds seconds -1, nanos 999999999, while duration('-1ns') holds seconds 0, nanos -1.
Expected
Duration arithmetic and equality are correct for negative durations.
Environment
- swamp main at d693eeaf6
- cel-js 7.6.1
Likely needs an upstream fix in cel-js (normalise nanos to one sign convention), or a swamp-side duration overload.
Shipped
Click a lifecycle step above to view its details.
Sign in to post a ripple.