From 9c4e49c0cb14b94eca4371b7c0e89f9b2c168eef Mon Sep 17 00:00:00 2001 From: Raymond Wagner Date: Fri, 28 Sep 2012 16:43:29 -0400 Subject: [PATCH] Force all datetime objects to be timezone aware. This works around some strangeness in the modified datetime class due to it being derived from a native C object. The timezone was being set to None in the base class's __new__ function, and the corrected timezone was ignored when set by the derived class's __init__. --- mythtv/bindings/python/MythTV/utility/dt.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/mythtv/bindings/python/MythTV/utility/dt.py b/mythtv/bindings/python/MythTV/utility/dt.py index 9a2b1853b14..a7aafd114aa 100644 --- a/mythtv/bindings/python/MythTV/utility/dt.py +++ b/mythtv/bindings/python/MythTV/utility/dt.py @@ -411,12 +411,22 @@ def duck(cls, t): pass raise TypeError("time data '%s' does not match supported formats"%t) - def __init__(self, year, month, day, hour=None, minute=None, second=None, - microsecond=None, tzinfo=None): + def __new__(cls, year, month, day, hour=None, minute=None, second=None, + microsecond=None, tzinfo=None): + if tzinfo is None: - tzinfo = self.localTZ() - super(datetime, self).__init__(year, month, day, hour, minute, second,\ - microsecond, tzinfo) + kwargs = {'tzinfo':cls.localTZ()} + else: + kwargs = {'tzinfo':tzinfo} + if hour is not None: + kwargs['hour'] = hour + if minute is not None: + kwargs['minute'] = minute + if second is not None: + kwargs['second'] = second + if microsecond is not None: + kwargs['microsecond'] = microsecond + return _pydatetime.__new__(cls, year, month, day, **kwargs) def mythformat(self): return self.astimezone(self.UTCTZ()).strftime('%Y%m%d%H%M%S')