"""Reconstruct time-zone behavior; does not run a scheduler or cloud service.""" import csv import hashlib import json import platform from datetime import datetime, timedelta, timezone from pathlib import Path from zoneinfo import TZPATH, ZoneInfo ROOT = Path(__file__).parent zone = ZoneInfo('America/New_York') UTC = timezone.utc def candidates(local): found = set() for fold in (0, 1): candidate = local.replace(tzinfo=zone, fold=fold).astimezone(UTC) if candidate.astimezone(zone).replace(tzinfo=None) == local: found.add(candidate.isoformat()) return sorted(found) days = [datetime(2026, 3, d, 9, tzinfo=zone) for d in (7, 8, 9)] rows = [] for i, local in enumerate(days): fixed = days[0].astimezone(UTC) + timedelta(hours=24*i) rows.append({'date':local.date().isoformat(), 'local_rule':local.isoformat(), 'local_rule_utc':local.astimezone(UTC).isoformat(), 'fixed_24h_local':fixed.astimezone(zone).isoformat()}) elapsed = (days[1].astimezone(UTC)-days[0].astimezone(UTC)).total_seconds()/3600 gap = candidates(datetime(2026,3,8,2,30)) fold = candidates(datetime(2026,11,1,1,30)) assert elapsed == 23 and not gap and len(fold) == 2 assert rows[1]['fixed_24h_local'].startswith('2026-03-08T10:00:00') source = next((Path(t)/'America/New_York' for t in TZPATH if (Path(t)/'America/New_York').exists()),None) data = {'python':platform.python_version(),'zone':'America/New_York','tzif_sha256':hashlib.sha256(source.read_bytes()).hexdigest() if source else 'tzdata package','spring_elapsed_hours':elapsed,'gap_candidates':gap,'fold_candidates':fold,'schedule_rows':rows} (ROOT/'results.json').write_text(json.dumps(data,indent=2)+'\n') with (ROOT/'schedule.csv').open('w',newline='') as f: w=csv.DictWriter(f,fieldnames=rows[0].keys());w.writeheader();w.writerows(rows) print(json.dumps(data,indent=2))