Skip to content

Commit 16b698b

Browse files
committed
merge
2 parents d7ac00e + 1dcf4f9 commit 16b698b

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

Lib/test/datetimetester.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3463,6 +3463,14 @@ def test_astimezone_default_eastern(self):
34633463
self.assertEqual(dt, local)
34643464
self.assertEqual(local.strftime("%z %Z"), "-0400 EDT")
34653465

3466+
@support.run_with_tz('EST+05EDT,M3.2.0,M11.1.0')
3467+
def test_astimezone_default_near_fold(self):
3468+
# Issue #26616.
3469+
u = datetime(2015, 11, 1, 5, tzinfo=timezone.utc)
3470+
t = u.astimezone()
3471+
s = t.astimezone()
3472+
self.assertEqual(t.tzinfo, s.tzinfo)
3473+
34663474
def test_aware_subtract(self):
34673475
cls = self.theclass
34683476

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ Core and Builtins
232232
Library
233233
-------
234234

235+
- Issue #26616: Fixed a bug in datetime.astimezone() method.
236+
235237
- Issue #26637: The :mod:`importlib` module now emits an :exc:`ImportError`
236238
rather than a :exc:`TypeError` if :func:`__import__` is tried during the
237239
Python shutdown process but :data:`sys.path` is already cleared (set to

Modules/_datetimemodule.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4753,7 +4753,12 @@ local_timezone(PyDateTime_DateTime *utc_time)
47534753
PyObject *nameo = NULL;
47544754
const char *zone = NULL;
47554755

4756-
delta = datetime_subtract((PyObject *)utc_time, PyDateTime_Epoch);
4756+
delta = new_delta(ymd_to_ord(GET_YEAR(utc_time), GET_MONTH(utc_time),
4757+
GET_DAY(utc_time)) - 719163,
4758+
60 * (60 * DATE_GET_HOUR(utc_time) +
4759+
DATE_GET_MINUTE(utc_time)) +
4760+
DATE_GET_SECOND(utc_time),
4761+
0, 0);
47574762
if (delta == NULL)
47584763
return NULL;
47594764
one_second = new_delta(0, 1, 0, 0);

0 commit comments

Comments
 (0)