From dfdb71b95180e14ed7a53aa78bda4a914485d0f3 Mon Sep 17 00:00:00 2001 From: burivuh Date: Fri, 1 Nov 2019 17:29:58 +0300 Subject: [PATCH 1/3] Update ccode.py --- snippets/pyaloha/ccode.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/snippets/pyaloha/ccode.py b/snippets/pyaloha/ccode.py index fb2258e..0ea79eb 100644 --- a/snippets/pyaloha/ccode.py +++ b/snippets/pyaloha/ccode.py @@ -55,7 +55,10 @@ def __init__(self, server_dtime, client_dtime): @property def is_accurate(self): - return self.dtime == self.client_creation + client_dtime = SerializableDatetime.utcfromtimestamp( + self.client_creation / 1000. # timestamp is in millisecs + ) + return self.dtime == client_dtime def __dumpdict__(self): return { From 776c0190f37165bc435856763a0c2b7481ec93cb Mon Sep 17 00:00:00 2001 From: burivuh Date: Fri, 1 Nov 2019 17:55:15 +0300 Subject: [PATCH 2/3] Update ccode.py --- snippets/pyaloha/ccode.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/snippets/pyaloha/ccode.py b/snippets/pyaloha/ccode.py index 0ea79eb..e34a50a 100644 --- a/snippets/pyaloha/ccode.py +++ b/snippets/pyaloha/ccode.py @@ -41,24 +41,24 @@ class PythonEventTime(object): delta_future = 1 * msec_in_a_day def __init__(self, server_dtime, client_dtime): - if client_dtime < server_dtime - self.delta_past or\ - client_dtime > server_dtime + self.delta_future: - dtime = server_dtime - else: - dtime = client_dtime - self.client_creation = client_dtime self.server_upload = server_dtime + + if self.is_accurate: + dtime = client_dtime + else: + dtime = server_dtime + self.dtime = SerializableDatetime.utcfromtimestamp( dtime / 1000. # timestamp is in millisecs ) @property def is_accurate(self): - client_dtime = SerializableDatetime.utcfromtimestamp( - self.client_creation / 1000. # timestamp is in millisecs - ) - return self.dtime == client_dtime + if self.client_creation > self.server_upload - self.delta_past and\ + self.client_creation < self.server_upload + self.delta_future: + return True + return False def __dumpdict__(self): return { From 9560314d97669bf1352275fd1bdcbc456880a69d Mon Sep 17 00:00:00 2001 From: burivuh Date: Tue, 5 Nov 2019 13:02:38 +0300 Subject: [PATCH 3/3] Remove is_accurate from serialization --- snippets/pyaloha/ccode.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/snippets/pyaloha/ccode.py b/snippets/pyaloha/ccode.py index e34a50a..30e1711 100644 --- a/snippets/pyaloha/ccode.py +++ b/snippets/pyaloha/ccode.py @@ -62,8 +62,7 @@ def is_accurate(self): def __dumpdict__(self): return { - 'dtime': self.dtime, - 'is_accurate': self.is_accurate + 'dtime': self.dtime }