Metadata-Version: 2.4
Name: dst-test-vectors
Version: 0.1.0
Summary: DST test vectors for nonexistent (gap) and ambiguous (overlap) local times, with helpers to test your timezone code. Standard library only.
Author-email: Plainfold <plainfoldhq@proton.me>
License-Expression: MIT
Project-URL: Homepage, https://github.com/plainfoldhq/tz-transitions
Project-URL: DST dates by country, https://plainfoldhq.github.io/dst-dates/
Keywords: dst,daylight saving time,timezone,time zone,tzdata,zoneinfo,test vectors,ambiguous time,nonexistent time,testing
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: tzdata
Requires-Dist: tzdata; extra == "tzdata"
Dynamic: license-file

# Time zone transitions table + DST test vectors (IANA tzdata, 1970-2050)

[![tests](https://github.com/plainfoldhq/tz-transitions/actions/workflows/tests.yml/badge.svg)](https://github.com/plainfoldhq/tz-transitions/actions/workflows/tests.yml)

A database-ready table of every UTC offset change (DST start/end and permanent offset changes) for IANA time zones, and DST edge-case test vectors for testing date-time code: nonexistent local times in spring-forward gaps, ambiguous times in fall-back overlaps, 30-minute DST (Lord Howe), +12:45/+13:45 (Chatham), changes at midnight (Havana).

Generated by script from the public-domain [IANA tz database](https://www.iana.org/time-zones) (tzdata 2026f) and checked against `zdump`, Python `zoneinfo` and JavaScript `Intl`. Made by Plainfold with AI assistance. Not affiliated with IANA.

## Reference pages

[Daylight saving time dates by country, by year](https://plainfoldhq.github.io/dst-dates/), generated from the same tzdata.

## Guides
- [Testing DST gaps and overlaps: nonexistent and ambiguous local times](https://github.com/plainfoldhq/tz-transitions/blob/main/docs/dst-gaps-overlaps-test-cases.md)
- [Convert UTC to local time in SQL with a transitions table](https://github.com/plainfoldhq/tz-transitions/blob/main/docs/convert-utc-to-local-time-sql.md) (PostgreSQL, MySQL/MariaDB)

## Python package: `dst-test-vectors` (coming to PyPI)
Test your own time zone code against the vectors. Standard library only, Python 3.10+. Not on PyPI yet; install from this repo for now:

```
pip install git+https://github.com/plainfoldhq/tz-transitions
```

```python
import dst_test_vectors as dtv

dtv.is_nonexistent("2026-03-08T02:30:00", "America/New_York")  # True: spring-forward gap
dtv.is_ambiguous("2026-11-01T01:30:00", "America/New_York")    # True: fall-back overlap

# Your function: (zone, naive local datetime) -> aware UTC datetime
def my_to_utc(zone, local): ...

assert dtv.check(my_to_utc) == []                     # "compatible" policy: earlier instant in overlaps, shift gaps forward
dtv.check(my_to_utc, policy="raise")                  # gaps must raise
dtv.check(my_to_utc, policy="later", zone="Europe/London")

# pytest
# @pytest.mark.parametrize("zone,local,expected", dtv.params(kind="gap"))
```

`dtv.cases(zone=..., kind="gap"|"overlap"|"normal", tag="midnight"|"odd_offset"|"delta_30min", year=...)` returns the bundled cases (the 36-case 2026 sample below). `dtv.load(path)` / `cases(path=...)` read any file in the same format, such as the full set's `dst_test_vectors.json`. CLI: `dst-test-vectors --zone Pacific/Chatham`, and `dst-test-vectors --check` to check this machine's `zoneinfo` (the helpers use your local tz database or the `tzdata` package; vectors are built from tzdata 2026f, so an older database can disagree, e.g. Cuba's 2026 rules).

## Free sample (this repo)
| File | What |
|---|---|
| `sample/transitions_sample_2026_2030.csv` | 118 transitions, 2026-2030, for 12 of these 16 zones: New York, Chicago, Denver, Los Angeles, Sao Paulo, London, Berlin, Kolkata, Tokyo, Sydney, Lord Howe, Auckland, Chatham, Havana, Tehran, Cairo (Sao Paulo, Kolkata, Tokyo and Tehran have no changes in 2026-2030; they are in the zones file) |
| `sample/zones_sample.csv` | Those 16 zones: countries, coordinates, offset at 1970, 2026 winter/summer offsets |
| `sample/dst_test_vectors_sample.json` | 36 DST test cases for 2026 in 5 zones |
| `src/dst_test_vectors/` | The `dst-test-vectors` package (bundles the same 36 cases) |
| `tests/test_vectors.py`, `tests/check_vectors.mjs` | Check the vectors with Python `zoneinfo` and JavaScript `Intl` (no dependencies); copy them to test your own code |

Columns of the transitions table: `zone, utc, unix, local_before, local_after, offset_before_s, offset_after_s, delta_s, dst_before_s, dst_after_s, is_dst_after, abbr_before, abbr_after, kind` (`gap`, `overlap`, `no_offset_change`). Offsets are seconds east of UTC. DST columns follow tzdata, which uses negative DST for Europe/Dublin and Africa/Casablanca, so use `dst_after_s > 0` for "summer time in effect".

Find the offset in effect at an instant: take the zone's latest row with `utc <= t` and use `offset_after_s`; before the first row, use the zone's offset at 1970.

## Full set ($15, one-time)
[Buy the full set on Polar](https://buy.polar.sh/polar_cl_IbPBiFVd3r1YmjO4XDcsCvCTG1DqmQIOPmld92JZG2z) (Polar is the merchant of record and handles sales tax). It contains:
- all 21,026 transitions 1970-2050 (280 of the 344 canonical zones change in that span; the zones table lists all 344), as CSV, SQLite and Parquet; zones table; 253 links (aliases)
- 51,404 DST test vectors for 2000-2050, every zone, tagged (`odd_offset`, `delta_30min`, `midnight`, `crosses_date`, ...)
- PostgreSQL loader with a `tz_offset_s(zone, timestamptz)` function and a MySQL/MariaDB loader (both tested), SQL Server script
- the generator, to rebuild from any newer tzdata, and the full test suite (every transition matches `zdump`)

Also sold as part of the [calendar data bundle](https://buy.polar.sh/polar_cl_HiUeTqJE1gUqHdb3OlOWb6Jml7pdq8E71O2pA4Y9iQ3): this pack plus the other two Plainfold calendar data packs (business days, date dimension, time zone transitions) for $35 instead of $49.

## Limits
- Future rows follow rules announced as of the tzdata release; governments change rules several times a year.
- The tz database is not a historical reference before 1970.

## Related
- [plainfoldhq/date-dimension](https://github.com/plainfoldhq/date-dimension): date dimension table and 4-5-4 / 4-4-5 retail calendars.
- [plainfoldhq/us-federal-calendar](https://github.com/plainfoldhq/us-federal-calendar): US federal holidays, NYSE trading days, Federal Reserve holidays.

## License
Code: MIT. Data: CC0 1.0 (public domain). Questions: plainfoldhq@proton.me.
