pytz: Why is normalize needed when converting between timezones?

后端 未结 2 1049
执笔经年
执笔经年 2020-12-15 04:59

I\'m reading the not so complete pytz documentation and I\'m stuck on understand one part of it.

Converting between timezones also needs special atten

相关标签:
2条回答
  • 2020-12-15 05:40

    From the pytz documentation:

    In addition, if you perform date arithmetic on local times that cross DST boundaries, the results may be in an incorrect timezone (ie. subtract 1 minute from 2002-10-27 1:00 EST and you get 2002-10-27 0:59 EST instead of the correct 2002-10-27 1:59 EDT). A normalize() method is provided to correct this. Unfortunately these issues cannot be resolved without modifying the Python datetime implementation.

    0 讨论(0)
  • 2020-12-15 05:42

    The docs say that normalize is used as a workaround for DST issues:

    In addition, if you perform date arithmetic on local times that cross DST boundaries, the results may be in an incorrect timezone (ie. subtract 1 minute from 2002-10-27 1:00 EST and you get 2002-10-27 0:59 EST instead of the correct 2002-10-27 1:59 EDT). A normalize() method is provided to correct this.

    So it's used to correct some edge cases involving DST. If you're not using DST timezones (e.g. UTC) then it's not necessary to use normalize.

    If you don't use it your conversion could potentially be one hour off under certain circumstances.

    0 讨论(0)
提交回复
热议问题