Conflicting localized datetime object for same timezone

Question:

I am getting two different time offset using US/Eastern pytz timezone.

>>> from pytz import timezone
    import datetime
    
    tz = timezone('US/Eastern')

>>> tz.localize(datetime.datetime(2021, 11, 1, 21, 1, 0))

2021-11-01 21:01:00-04:00

>>> tz.localize(datetime.datetime(2020, 11, 1, 21, 1, 0))

2020-11-01 21:01:00-05:00

Why am I getting different time offsets for the same timezones?

Asked By: deadlock

||

Answers:

US/Eastern timezone switch to standard/winter time in first Sunday of November.
Which in 2020 was 1 November 2020, and in 2021 was 7 November 2021
i.e. on 1 November 2021 DST was still on.

You can check Is a specific timezone using DST right now? on how to check if DST is on.

Answered By: buran
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.