summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorAlexander Belopolsky <abalkin@users.noreply.github.com>2023-04-19 21:02:29 (GMT)
committerGitHub <noreply@github.com>2023-04-19 21:02:29 (GMT)
commit2b1260c55763a952c57b92fe0f274b6ee79efd05 (patch)
treef5d51ee35c77495a6ceee99fc4de216fdd9d2d06 /Modules
parentd4aa8578b18d12380c841de96e8f80cac52bf61a (diff)
downloadcpython-2b1260c55763a952c57b92fe0f274b6ee79efd05.zip
cpython-2b1260c55763a952c57b92fe0f274b6ee79efd05.tar.gz
cpython-2b1260c55763a952c57b92fe0f274b6ee79efd05.tar.bz2
gh-83861: Fix datetime.astimezone() method (GH-101545)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_datetimemodule.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index eda8c56..f317dc1 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -6153,17 +6153,31 @@ local_to_seconds(int year, int month, int day,
static PyObject *
local_timezone_from_local(PyDateTime_DateTime *local_dt)
{
- long long seconds;
+ long long seconds, seconds2;
time_t timestamp;
+ int fold = DATE_GET_FOLD(local_dt);
seconds = local_to_seconds(GET_YEAR(local_dt),
GET_MONTH(local_dt),
GET_DAY(local_dt),
DATE_GET_HOUR(local_dt),
DATE_GET_MINUTE(local_dt),
DATE_GET_SECOND(local_dt),
- DATE_GET_FOLD(local_dt));
+ fold);
if (seconds == -1)
return NULL;
+ seconds2 = local_to_seconds(GET_YEAR(local_dt),
+ GET_MONTH(local_dt),
+ GET_DAY(local_dt),
+ DATE_GET_HOUR(local_dt),
+ DATE_GET_MINUTE(local_dt),
+ DATE_GET_SECOND(local_dt),
+ !fold);
+ if (seconds2 == -1)
+ return NULL;
+ /* Detect gap */
+ if (seconds2 != seconds && (seconds2 > seconds) == fold)
+ seconds = seconds2;
+
/* XXX: add bounds check */
timestamp = seconds - epoch;
return local_timezone_from_timestamp(timestamp);