#4284·date-fns

`addDays` produces an unexpected date when `amount` is a string

Author: pythonpioneerCreated Aug 7, 2026Updated Aug 26, 2026

Description

While testing addDays, I noticed that passing a string as the amount parameter results in a seemingly valid but unexpected date instead of either rejecting the input or producing a more obvious result.

Reproduction

javascript
import { addDays } from 'date-fns';

const result1 = addDays(new Date(2026, 8, 10), 10);
/* 2026-09-19T18:30:00.000Z */

const result2 = addDays(new Date(2026, 8, 10), '10');
/* 2629-06-05T18:30:00.000Z */

const result3 = addDays(new Date(2026, 8, 10), 1000);
/* 2629-06-05T18:30:00.000Z */

console.log({ result1, result2, result3 });

Expected Behavior

Since amount is documented as a number, I expected passing a string to either:

  • be rejected (e.g. return Invalid Date or otherwise fail predictably), or
  • behave consistently with the numeric value 10 if numeric strings are intentionally supported.

Instead, passing "10" results in a completely different valid date due to JavaScript string concatenation.

Possible cause

It appears the implementation performs arithmetic similar to:

javascript
date.setDate(date.getDate() + amount);

When amount is a string:

javascript
10 + "10" // => "1010"

which effectively becomes:

javascript
date.setDate(1010);

This results in a valid but unintended date.

Question

Is this the intended behavior for unsupported input, or would it make sense for addDays to fail more predictably when amount is not a number?

I suspect the same behavior may also exist in other add* utilities that accept an amount parameter, as they may follow a similar implementation pattern.

If this is considered unintended behavior, I'd be happy to work on a PR to address it.