Open thiaagodev opened 2 years ago
Drive-by comment:
1) You should always include steps to reproduce the problem.
2) I don't see any problems with America/Sao_Paulo:
from datetime import datetime, timedelta
from pytz import timezone
import pytz
sao_paulo_tz = timezone('America/Sao_Paulo')
pacific_tz = timezone('US/Pacific')
now = datetime.now(pytz.utc)
print(now)
pacific_dt = now.astimezone(pacific_tz)
print(pacific_dt)
sao_dt = now.astimezone(sao_paulo_tz)
print(sao_dt)
prints
2021-12-24 00:35:47.459424+00:00
2021-12-23 16:35:47.459424-08:00
2021-12-23 21:35:47.459424-03:00
3) You are probably using pytz
incorrectly. It has a few quirks. If you are able to, you should use zoneinfo (Python >= 3.9) or backports.zoneinfo (Python < 3.9) instead.
There is an inconsistency when converting a datetime that is in UTC to pytz.timezone('America/Sao_Paulo'), instead of discounting 3 hours, it is only discounting 2 hours, the library is considering that Brazil is in daylight saving time, that no longer exists.
To get the correct conversion, you need to use pytz.timezone('Etc/GMT+3')
Fix the 'America/Sao_Paulo' to discount the hours in the correct way