#!/usr/bin/env python3 # Standalone synthetic fixture; no user files or external network. from datetime import datetime,timezone from zoneinfo import ZoneInfo,TZPATH from pathlib import Path import hashlib def candidates(local,zone): tz=ZoneInfo(zone);wall=datetime.fromisoformat(local);out={} for fold in (0,1): attached=wall.replace(tzinfo=tz,fold=fold);utc=attached.astimezone(timezone.utc);back=utc.astimezone(tz) if back.replace(tzinfo=None)==wall: out[utc.isoformat()]={'fold':back.fold,'localWithOffset':back.isoformat(),'utc':utc.isoformat(),'roundTrip':True} return list(out.values()) inputs=[('fall-fold','2026-11-01T01:30:00','America/New_York'),('spring-gap','2026-03-08T02:30:00','America/New_York'),('ordinary','2026-10-15T09:00:00','America/New_York'),('seoul','2026-11-01T01:30:00','Asia/Seoul')] rows=[{'case':name,'local':local,'zone':zone,'candidates':candidates(local,zone)}for name,local,zone in inputs] assert [len(r['candidates'])for r in rows]==[2,0,1,1] a=datetime(2026,11,1,1,30,tzinfo=ZoneInfo('America/New_York'),fold=0);b=a.replace(fold=1) wall=(b-a).total_seconds();utc=(b.astimezone(timezone.utc)-a.astimezone(timezone.utc)).total_seconds() assert wall==0 and utc==3600 fingerprint=None for root in TZPATH: p=Path(root)/'America/New_York' if p.is_file():fingerprint=hashlib.sha256(p.read_bytes()).hexdigest();break result={'cases':rows,'sameZoneComparison':{'equal':a==b,'wallDeltaSeconds':wall,'utcDeltaSeconds':utc,'timestampDifferenceSeconds':b.timestamp()-a.timestamp()},'zoneFileSha256':fingerprint,'scope':'Current installed IANA timezone data, recorded zone-file fingerprint if available. No booking or scheduler tested. Future timezone law/data changes can alter future results; UTC plus zone/original input preserve different facts.'} import sys,json from datetime import datetime,timezone result={'experiment':'dst-ambiguous-local-times','executedAt':datetime.now(timezone.utc).isoformat(),'runtime':sys.version.split()[0],'synthetic':True,**result} print(json.dumps(result,ensure_ascii=False,indent=2))