-
Notifications
You must be signed in to change notification settings - Fork 99
timezone error in parse_rfc822 #285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The internal utility parse_rfc822 converts string to local time, and this is by-design. |
docker: date +"%Z %z"
> CST +0800
date
> Tue May 20 17:22:34 CST 2025 mac: systemsetup -gettimezone
> Time Zone: Asia/Shanghai
date
> Tue May 20 17:22:07 CST 2025 Mac timezone and docker timezone is same , but |
UTC debug output: zdump -v /usr/share/zoneinfo/UTC | tail
/usr/share/zoneinfo/UTC Sat Apr 14 17:59:59 1990 UT = Sun Apr 15 01:59:59 1990 CST isdst=0 gmtoff=28800
/usr/share/zoneinfo/UTC Sat Apr 14 18:00:00 1990 UT = Sun Apr 15 03:00:00 1990 CDT isdst=1 gmtoff=32400
/usr/share/zoneinfo/UTC Sat Sep 15 16:59:59 1990 UT = Sun Sep 16 01:59:59 1990 CDT isdst=1 gmtoff=32400
/usr/share/zoneinfo/UTC Sat Sep 15 17:00:00 1990 UT = Sun Sep 16 01:00:00 1990 CST isdst=0 gmtoff=28800
/usr/share/zoneinfo/UTC Sat Apr 13 17:59:59 1991 UT = Sun Apr 14 01:59:59 1991 CST isdst=0 gmtoff=28800
/usr/share/zoneinfo/UTC Sat Apr 13 18:00:00 1991 UT = Sun Apr 14 03:00:00 1991 CDT isdst=1 gmtoff=32400
/usr/share/zoneinfo/UTC Sat Sep 14 16:59:59 1991 UT = Sun Sep 15 01:59:59 1991 CDT isdst=1 gmtoff=32400
/usr/share/zoneinfo/UTC Sat Sep 14 17:00:00 1991 UT = Sun Sep 15 01:00:00 1991 CST isdst=0 gmtoff=28800
/usr/share/zoneinfo/UTC 9223372036854689407 = NULL
/usr/share/zoneinfo/UTC 9223372036854775807 = NULL docker_good usr/share/zoneinfo/UTC -9223372036854775808 = NULL
/usr/share/zoneinfo/UTC -9223372036854689408 = NULL
/usr/share/zoneinfo/UTC 9223372036854689407 = NULL
/usr/share/zoneinfo/UTC 9223372036854775807 = NULL
|
Please show results returned by |
test_code from email.utils import parsedate_to_datetime
from datetime import timezone
s = "Thu, 05 Oct 2023 14:30:00 GMT"
dt = parsedate_to_datetime(s)
import zoneinfo
utc = zoneinfo.ZoneInfo("UTC")
dt = dt.astimezone(utc)
print(f"{dt} ({repr(dt.tzinfo)})") output
resolve from email.utils import parsedate_to_datetime
from datetime import timezone
s = "Thu, 05 Oct 2023 14:30:00 GMT"
dt = parsedate_to_datetime(s)
# import zoneinfo
# utc = zoneinfo.ZoneInfo("UTC")
# dt = dt.astimezone(utc)
if dt.tzinfo is not timezone.utc:
if dt.utcoffset() == timezone.utc.utcoffset(None):
dt = dt.replace(tzinfo=timezone.utc)
print(f"{dt} ({repr(dt.tzinfo)})") output
|
Therefore replacing |
Parse datetime string error in parse_rfc822.
parsedate_to_datetime
usedatetime.timezone.utc
inemail.utils
which depends local settings.test_code:
mac output:
docker output:
The text was updated successfully, but these errors were encountered: