cpython: 88a5f2730579 (original) (raw)

Mercurial > cpython

changeset 77569:88a5f2730579

Issue #9527: datetime.astimezone() method will now supply a class timezone instance corresponding to the system local timezone when called with no arguments. [#9527]

Alexander Belopolsky alexander.belopolsky@gmail.com
date Fri, 22 Jun 2012 12:23:23 -0400
parents ace45d23628a
children 336c53c1f547
files Doc/library/datetime.rst Lib/datetime.py Lib/test/datetimetester.py Misc/NEWS Modules/_datetimemodule.c
diffstat 5 files changed, 138 insertions(+), 12 deletions(-)[+] [-] Doc/library/datetime.rst 11 Lib/datetime.py 28 Lib/test/datetimetester.py 21 Misc/NEWS 4 Modules/_datetimemodule.c 86

line wrap: on

line diff

--- a/Doc/library/datetime.rst +++ b/Doc/library/datetime.rst @@ -958,17 +958,22 @@ Instance methods: datetime with no conversion of date and time data. -.. method:: datetime.astimezone(tz) +.. method:: datetime.astimezone(tz=None)

--- a/Lib/datetime.py +++ b/Lib/datetime.py @@ -1493,8 +1493,32 @@ class datetime(date): return datetime(year, month, day, hour, minute, second, microsecond, tzinfo)

mytz = self.tzinfo

--- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -1972,7 +1972,7 @@ class TestDateTime(TestDate): # simply can't be applied to a naive object. dt = self.theclass.now() f = FixedOffset(44, "")

@@ -3253,8 +3253,6 @@ class TestDateTimeTZ(TestDateTime, TZInf self.assertTrue(dt.tzinfo is f44m) # Replacing with degenerate tzinfo raises an exception. self.assertRaises(ValueError, dt.astimezone, fnone)

@@ -3274,6 +3272,23 @@ class TestDateTimeTZ(TestDateTime, TZInf self.assertTrue(got.tzinfo is expected.tzinfo) self.assertEqual(got, expected)

+

+ def test_aware_subtract(self): cls = self.theclass

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -40,6 +40,10 @@ Core and Builtins Library ------- +- Issue #9527: datetime.astimezone() method will now supply a class

--- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -4686,17 +4686,87 @@ datetime_replace(PyDateTime_DateTime *se } static PyObject * +local_timezone(PyObject *utc_time) +{

+

+#ifdef HAVE_STRUCT_TM_TM_ZONE

+#else /* HAVE_STRUCT_TM_TM_ZONE */

+#endif /* HAVE_STRUCT_TM_TM_ZONE */

+} + +static PyObject * datetime_astimezone(PyDateTime_DateTime *self, PyObject *args, PyObject *kw) { PyObject *result; PyObject *offset; PyObject *temp;

+

if (!HASTZINFO(self) || self->tzinfo == Py_None) @@ -4729,8 +4799,16 @@ datetime_astimezone(PyDateTime_DateTime /* Attach new tzinfo and let fromutc() do the rest. */ temp = ((PyDateTime_DateTime *)result)->tzinfo;