tiempo

addDays

Add days to a datetime (DST-safe)

Add days to a datetime. DST-safe—adds calendar days, not 24-hour periods.

Signature

function addDays(
  input: Temporal.Instant | Temporal.ZonedDateTime,
  days: number
): Temporal.ZonedDateTime

Parameters

ParameterTypeDescription
inputTemporal.Instant | Temporal.ZonedDateTimeThe datetime to add days to
daysnumberNumber of days to add (can be negative)

Returns

A Temporal.ZonedDateTime with the days added.

Examples

Basic usage

import { addDays } from '@gobrand/tiempo';

const instant = Temporal.Instant.from('2025-01-20T12:00:00Z');
addDays(instant, 5);
// 2025-01-25T12:00:00Z[UTC]

Preserves timezone

const zoned = Temporal.ZonedDateTime.from('2025-01-20T15:30:00-05:00[America/New_York]');
addDays(zoned, 10);
// 2025-01-30T15:30:00-05:00[America/New_York]

Negative values subtract

addDays(instant, -7);
// 2025-01-13T12:00:00Z[UTC]

DST Handling

addDays properly handles Daylight Saving Time transitions:

import { addDays, addHours } from '@gobrand/tiempo';

// DST transition in US (March 9, 2025 at 2:00 AM)
const beforeDst = Temporal.ZonedDateTime.from('2025-03-08T12:00:00-05:00[America/New_York]');

// Adding 1 day = calendar day (still 12:00 PM)
const nextDay = addDays(beforeDst, 1);
// 2025-03-09T12:00:00-04:00[America/New_York]

// Compare with addHours: Adding 24 hours = 24 hours of elapsed time
const plus24h = addHours(beforeDst, 24);
// 2025-03-09T13:00:00-04:00[America/New_York]
// (One hour later because DST "lost" an hour)

On this page