Skip to content

Instantly share code, notes, and snippets.

@kgriffs
Last active February 13, 2024 19:22
Show Gist options
  • Save kgriffs/0321be9e627bf42a6dae31028a2523e3 to your computer and use it in GitHub Desktop.
Save kgriffs/0321be9e627bf42a6dae31028a2523e3 to your computer and use it in GitHub Desktop.

Revisions

  1. kgriffs revised this gist Feb 13, 2024. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions example.py
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,9 @@
    print("Original DST Active Offset (America/New_York):", dt_aware_dst_active.dst())
    print("Original DST Active (America/New_York):", dt_aware_dst_active)
    print("To UTC, DST Active (America/New_York):", dt_aware_dst_active.astimezone(pytz.utc))
    print("Roundtrip, DST Active (America/New_York):", dt_aware_dst_active.astimezone(pytz.utc).astimezone(tz_ny))
    print()
    print("Original DST Inactive Offset (America/New_York):", dt_aware_dst_inactive.dst())
    print("Original DST Inctive (America/New_York):", dt_aware_dst_inactive)
    print("To UTC, DST Inctive (America/New_York):", dt_aware_dst_inactive.astimezone(pytz.utc))
    print("Original DST Inactive (America/New_York):", dt_aware_dst_inactive)
    print("To UTC, DST Inactive (America/New_York):", dt_aware_dst_inactive.astimezone(pytz.utc))
    print("Roundtrip, DST Inactive (America/New_York):", dt_aware_dst_inactive.astimezone(pytz.utc).astimezone(tz_ny))
  2. kgriffs created this gist Feb 13, 2024.
    15 changes: 15 additions & 0 deletions example.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    import datetime
    import pytz

    tz_ny = pytz.timezone('America/New_York')

    dt_aware_dst_active = tz_ny.localize(datetime.datetime(2023, 5, 1, 12, 0))
    dt_aware_dst_inactive = tz_ny.localize(datetime.datetime(2023, 12, 1, 12, 0))

    print("Original DST Active Offset (America/New_York):", dt_aware_dst_active.dst())
    print("Original DST Active (America/New_York):", dt_aware_dst_active)
    print("To UTC, DST Active (America/New_York):", dt_aware_dst_active.astimezone(pytz.utc))
    print()
    print("Original DST Inactive Offset (America/New_York):", dt_aware_dst_inactive.dst())
    print("Original DST Inctive (America/New_York):", dt_aware_dst_inactive)
    print("To UTC, DST Inctive (America/New_York):", dt_aware_dst_inactive.astimezone(pytz.utc))