﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc	mlocked
13299	Python Bindings fail to calculate date-time object	rcrdnalor	Raymond Wagner	"Somewhere after Ubuntu 14.04 the content of the time-zoneinfo files in 
/usr/share/zoneinfo/* changed by introducing a reference to the 
Local Mean Time (LMT) from Year, Month, Date (1,1,1) to
the first introduction of time zones: 
This is a very huge value, even the ""zdump"" utility for the zoneinfo files cannot cope with this. 
This change causes the Python bindings to fail when calculating
time transitions (File: dt.py, class: posixtzinfo, method: _process).
Unfortunately, this exception is silently covered by datetime.duck() at line 437 (https://github.com/MythTV/mythtv/blob/fixes/29/mythtv/bindings/python/MythTV/utility/dt.py#L434):
{{{
        try:
            # existing built-in datetime
            return cls.fromDatetime(t)
        except: pass
}}}

If you change it to raise an exception, one will see the backtrace:
{{{
Traceback (most recent call last):
  File ""./timetest_local.py"", line 4, in <module>
    from MythTV import datetime
  File ""/home/local-user/MythTV_v_29_fixes/test/MythTV/__init__.py"", line 41, in <module>
    from .dataheap import *
  File ""/home/local-user/MythTV_v_29_fixes/test/MythTV/dataheap.py"", line 665, in <module>
    class Job( DBDataWrite, JOBTYPE, JOBCMD, JOBFLAG, JOBSTATUS ):
  File ""/home/local-user/MythTV_v_29_fixes/test/MythTV/dataheap.py"", line 671, in Job
    _defaults = {'id':None,     'inserttime':datetime.now(),
  File ""/home/local-user/MythTV_v_29_fixes/test/MythTV/utility/dt.py"", line 303, in now
    tz = cls.localTZ()
  File ""/home/local-user/MythTV_v_29_fixes/test/MythTV/utility/dt.py"", line 273, in localTZ
    cls._localtz = posixtzinfo()
  File ""/home/local-user/MythTV_v_29_fixes/test/MythTV/utility/singleton.py"", line 49, in __call__
    inst = type.__call__(cls, *args, **kwargs)
  File ""/home/local-user/MythTV_v_29_fixes/test/MythTV/utility/dt.py"", line 219, in __init__
    self._process(fd, version)
  File ""/home/local-user/MythTV_v_29_fixes/test/MythTV/utility/dt.py"", line 163, in _process
    tt = time.gmtime(t)
ValueError: (75, 'Value too large for defined data type')
}}}

Please see attachment for the setup of timezones of my PC.

This failure causes a wrong time calculation of the MythTV Python Bindings,
i.e.: the calculated time-zone is off by an hour:

{{{
$ timedatectl
                      Local time: So 2018-07-01 10:59:06 CEST
                  Universal time: So 2018-07-01 08:59:06 UTC
                        RTC time: So 2018-07-01 08:59:06
                       Time zone: Europe/Vienna (CEST, +0200)
       System clock synchronized: yes
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

$ python2
>>> from MythTV import datetime
>>> import time
>>> tnow = time.time()
>>> datetime.fromtimestamp(tnow).strftime(""%Y%m%d%H%M%S %z"")
'20180701100955 +0100'
}}}


The attached patch adds robustness to the method ""posixtzinfo._process()"" by simply eliminating values that are out of range for the python data type. 
The resulting ""transitions"" object ot the class ""posixtzinfo"" is identical to those one created on Ubuntu 14.04 with mythtv_0.27_fixes (without the patch).

With this patch, I get the correct result when asking mythtv-python for the current time:
{{{
$ python2
>>> from MythTV import datetime
>>> import time
>>> tnow = time.time()
>>> datetime.fromtimestamp(tnow).strftime(""%Y%m%d%H%M%S %z"")
'20180701110458 +0200'
}}}

Please note: I need this method to create 'xmltv' files for mythtv.
The attached patch is against fixes/29, but compatible to master as well.
Once accepted, plase backport to fixes/29.



 

"	Patch - Bug Fix	closed	minor	31.0	Bindings - Python	Master Head	medium	Fixed			0
