~martijnbraam/shipments

7d019ee11a1bd0d76be227eb8f194a1a8db23923 — Martijn Braam 2 years ago d173de9
carrier: 4px: fix events with UTC timestamps
1 files changed, 7 insertions(+), 4 deletions(-)

M shipments/carrier.py
M shipments/carrier.py => shipments/carrier.py +7 -4
@@ 490,10 490,13 @@ class Track4PX(Carrier):
            result.status = 'Delivered'

        for event in payload['tracks']:
            _, tz = event['tkTimezone'].split('+')
            tz_hour, tz_min = tz.split(':')
            stamp = datetime.fromtimestamp(event['tkDate'] / 1000,
                                           tz=timezone(timedelta(hours=int(tz_hour, 10), minutes=int(tz_min, 10))))
            if '+' in event['tkTimezone']:
                _, tz = event['tkTimezone'].split('+')
                tz_hour, tz_min = tz.split(':')
                stamp = datetime.fromtimestamp(event['tkDate'] / 1000,
                                               tz=timezone(timedelta(hours=int(tz_hour, 10), minutes=int(tz_min, 10))))
            else:
                stamp = datetime.utcfromtimestamp(event['tkDate'] / 1000)
            e = PackageEvent(stamp, event['tkLocation'], event['tkDesc'])
            result.events.append(e)