From 575f682a61023f6f43e62039dfc2a2299d6db533 Mon Sep 17 00:00:00 2001 From: Sergei Turukin Date: Tue, 17 May 2016 13:54:42 +0300 Subject: [PATCH] Using `utcnow` helps to avoid timezone issues. On timer start timezone is provided to `datetime.now()` call, but on refresh is not. That cause a bug with wrong time difference (it include timezone diff). Didn't dig deep enough to figure out why there is inconsistency with timezones so just pin timezone info as it's not useful anyway. --- i3pystatus/pomodoro.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/i3pystatus/pomodoro.py b/i3pystatus/pomodoro.py index 2ccd5a1..2791cb6 100644 --- a/i3pystatus/pomodoro.py +++ b/i3pystatus/pomodoro.py @@ -6,7 +6,6 @@ from datetime import datetime, timedelta from i3pystatus import IntervalModule - class Pomodoro(IntervalModule): """ @@ -50,27 +49,27 @@ class Pomodoro(IntervalModule): self.time = None def run(self): - if self.time and datetime.now() >= self.time: + if self.time and datetime.utcnow() >= self.time: if self.state == 'running': self.state = 'break' if self.breaks == self.short_break_count: - self.time = datetime.now() + \ + self.time = datetime.utcnow() + \ timedelta(seconds=self.long_break_duration) self.breaks = 0 else: - self.time = datetime.now() + \ + self.time = datetime.utcnow() + \ timedelta(seconds=self.break_duration) self.breaks += 1 text = 'Go for a break!' else: self.state = 'running' - self.time = datetime.now() + \ + self.time = datetime.utcnow() + \ timedelta(seconds=self.pomodoro_duration) text = 'Back to work!' self._alarm(text) if self.state == 'running' or self.state == 'break': - min, sec = divmod((self.time - datetime.now()).total_seconds(), 60) + min, sec = divmod((self.time - datetime.utcnow()).total_seconds(), 60) text = '{:02}:{:02}'.format(int(min), int(sec)) color = self.color_running if self.state == 'running' else self.color_break else: @@ -82,7 +81,7 @@ class Pomodoro(IntervalModule): sdict = { 'time': text, - 'current_pomodoro': self.breaks, + 'current_pomodoro': self.breaks + 1, 'total_pomodoro': self.short_break_count + 1, } self.data = sdict @@ -93,7 +92,7 @@ class Pomodoro(IntervalModule): def start(self): self.state = 'running' - self.time = datetime.now() + timedelta(seconds=self.pomodoro_duration) + self.time = datetime.utcnow() + timedelta(seconds=self.pomodoro_duration) self.breaks = 0 def stop(self):