From 6ad3851afddd221655743a34be7d06a7be1815f4 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 29 Jan 2018 08:42:05 +1000 Subject: [PATCH] wacom: set the device time to UTC time on pairing And let us handle the local time zone conversions in the client, because having timestamps in localtime in the daemon is confusing and error-prone (how is the client supposed to know what localtime was?) --- README.md | 4 +++- tools/tuhi-kete.py | 2 +- tuhi/wacom.py | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 45d539c..fa98405 100644 --- a/README.md +++ b/README.md @@ -139,7 +139,9 @@ org.freedesktop.tuhi1.Device Property: DrawingsAvailable (at) An array of timestamps of the available drawings. The timestamp of - each drawing can be used as argument to GetJSONData(). + each drawing can be used as argument to GetJSONData(). Timestamps are + in seconds since the Epoch and may be used to display information to + the user or sort data. Read-only Property: Listening (b) diff --git a/tools/tuhi-kete.py b/tools/tuhi-kete.py index 03bc7b1..14c1012 100755 --- a/tools/tuhi-kete.py +++ b/tools/tuhi-kete.py @@ -502,7 +502,7 @@ class Fetcher(Worker): for idx in self.indices: jsondata = self.device.json(idx) data = json.loads(jsondata) - t = time.gmtime(data['timestamp']) + t = time.localtime(data['timestamp']) t = time.strftime('%Y-%m-%d-%H-%M', t) path = f'{data["devicename"]}-{t}.svg' self.json_to_svg(data, path) diff --git a/tuhi/wacom.py b/tuhi/wacom.py index d52d530..a131179 100644 --- a/tuhi/wacom.py +++ b/tuhi/wacom.py @@ -13,6 +13,7 @@ import binascii +import calendar import logging import threading import time @@ -268,7 +269,8 @@ class WacomDevice(GObject.Object): expected_opcode=0xb3) def set_time(self): - self.current_time = time.strftime("%y%m%d%H%M%S") + # Device time is UTC + self.current_time = time.strftime("%y%m%d%H%M%S", time.gmtime()) args = [int(i) for i in binascii.unhexlify(self.current_time)] self.send_nordic_command_sync(command=0xb6, expected_opcode=0xb3, @@ -463,7 +465,7 @@ class WacomDevice(GObject.Object): x, y, p = 0, 0, 0 dx, dy, dp = 0, 0, 0 - timestamp = int(time.mktime(timestamp)) + timestamp = int(calendar.timegm(timestamp)) drawings = [] drawing = None stroke = None