Skip to content

Commit

Permalink
WIP - add "naive" fix for C implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
abalkin committed Feb 6, 2023
1 parent d3b6683 commit b665d10
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b665d10

Please sign in to comment.