---
title: "Test times at the daylight saving changes · Agent Wranglers"
url: https://agentwranglers.se/playbook/testing/unit-tests/daylight-saving-tests
updated: 2026-10-21
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Test times at the daylight saving changes

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Unit tests](https://agentwranglers.se/playbook/testing/unit-tests.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers). Updated 2026-10-21.

- ID: TST-50
- Level: Recommended
- Chapter: [Unit tests](https://agentwranglers.se/playbook/testing/unit-tests)
- Rule: Every feature that schedules, repeats or bills by local time has tests on both clock changes of a year. One test covers the hour that is skipped, and one covers the hour that happens twice.
- How: In spring, a local time such as 02:30 does not exist in many zones. In autumn, 02:30 can happen twice. A daily reminder can then fire twice or not at all. A day can last 23 or 25 hours, so adding 24 hours is not the same as adding one day. Store instants in UTC and the person's time zone by its IANA name, such as `Europe/Stockholm`. Hold every time in code with its zone, as [keep the time zone on every time](https://agentwranglers.se/playbook/architecture/data-shapes/zone-aware-times) says. Do date arithmetic in that zone with a time zone library, never with fixed offsets. Fake the clock as [Fake the clock and the network in unit tests](https://agentwranglers.se/playbook/testing/unit-tests/unit-deterministic) says, and set it just before each change. Take the change dates from the IANA time zone database, because governments change them.
- Check: For each such feature, tests run on the spring and autumn change dates in at least two zones, such as `Europe/Stockholm` and `America/New_York`. A daily job set for 02:30 runs exactly once on each of those days. Adding one day across a change keeps the local time of day.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### Python example

```python
from datetime import datetime
from zoneinfo import ZoneInfo

STOCKHOLM = ZoneInfo("Europe/Stockholm")

def test_one_day_later_keeps_the_local_time_across_the_spring_change():
    before = datetime(2026, 3, 28, 9, 0, tzinfo=STOCKHOLM)
    assert next_reminder(before) == datetime(2026, 3, 29, 9, 0, tzinfo=STOCKHOLM)

def test_the_repeated_autumn_hour_runs_the_job_once():
    start = datetime(2026, 10, 25, 0, 0, tzinfo=STOCKHOLM)
    end = datetime(2026, 10, 25, 4, 0, tzinfo=STOCKHOLM)
    assert len(job_runs_between(start, end, daily_at="02:30")) == 1
```

### TypeScript example

```ts
import { DateTime } from 'luxon';
import { expect, test } from 'vitest';

const zone = 'Europe/Stockholm';

test('one day later keeps the local time across the spring change', () => {
  const before = DateTime.fromObject({ year: 2026, month: 3, day: 28, hour: 9 }, { zone });
  expect(nextReminder(before).toISO()).toBe('2026-03-29T09:00:00.000+02:00');
});

test('the repeated autumn hour runs the job once', () => {
  const start = DateTime.fromObject({ year: 2026, month: 10, day: 25, hour: 0 }, { zone });
  const end = DateTime.fromObject({ year: 2026, month: 10, day: 25, hour: 4 }, { zone });
  expect(jobRunsBetween(start, end, { dailyAt: '02:30' })).toHaveLength(1);
});
```

## Sources

- [Python zoneinfo](https://docs.python.org/3/library/zoneinfo.html)
- [IANA time zone database](https://www.iana.org/time-zones)

## Related rules

- [Keep the time zone on every time](https://agentwranglers.se/playbook/architecture/data-shapes/zone-aware-times) in Architecture
- [Fake the clock and the network in unit tests](https://agentwranglers.se/playbook/testing/unit-tests/unit-deterministic) in Testing

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/testing/unit-tests/daylight-saving-tests">Agent Wranglers testing playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Test sequences of actions against a simple model](https://agentwranglers.se/playbook/testing/unit-tests/stateful-property-tests)
- [Unit tests](https://agentwranglers.se/playbook/testing/unit-tests)
