diff --git a/Misc/NEWS.d/next/Windows/2023-07-24-13-35-22.gh-issue-107078.leZSPg.rst b/Misc/NEWS.d/next/Windows/2023-07-24-13-35-22.gh-issue-107078.leZSPg.rst new file mode 100644 index 00000000000000..82089f61a01aa2 --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2023-07-24-13-35-22.gh-issue-107078.leZSPg.rst @@ -0,0 +1 @@ +Fix `_datetimemodule.c` when calling `datetime.datetime.fromtimestamp(0).astimezone()` with `OSError` on Windows diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index b8cb0c012fd537..18842b379ca1a7 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -6333,9 +6333,18 @@ local_to_seconds(int year, int month, int day, u2 = u1 + max_fold_seconds; else u2 = u1 - max_fold_seconds; +#ifdef MS_WINDOWS + u2 += max_fold_seconds; +#endif + lt = local(u2); if (lt == -1) return -1; +#ifdef MS_WINDOWS + u2 -= max_fold_seconds; + lt -= max_fold_seconds; +#endif + b = lt - u2; if (a == b) return u1;