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.
This commit is contained in:
parent
4611295475
commit
575f682a61
@ -6,7 +6,6 @@ from datetime import datetime, timedelta
|
|||||||
|
|
||||||
from i3pystatus import IntervalModule
|
from i3pystatus import IntervalModule
|
||||||
|
|
||||||
|
|
||||||
class Pomodoro(IntervalModule):
|
class Pomodoro(IntervalModule):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -50,27 +49,27 @@ class Pomodoro(IntervalModule):
|
|||||||
self.time = None
|
self.time = None
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if self.time and datetime.now() >= self.time:
|
if self.time and datetime.utcnow() >= self.time:
|
||||||
if self.state == 'running':
|
if self.state == 'running':
|
||||||
self.state = 'break'
|
self.state = 'break'
|
||||||
if self.breaks == self.short_break_count:
|
if self.breaks == self.short_break_count:
|
||||||
self.time = datetime.now() + \
|
self.time = datetime.utcnow() + \
|
||||||
timedelta(seconds=self.long_break_duration)
|
timedelta(seconds=self.long_break_duration)
|
||||||
self.breaks = 0
|
self.breaks = 0
|
||||||
else:
|
else:
|
||||||
self.time = datetime.now() + \
|
self.time = datetime.utcnow() + \
|
||||||
timedelta(seconds=self.break_duration)
|
timedelta(seconds=self.break_duration)
|
||||||
self.breaks += 1
|
self.breaks += 1
|
||||||
text = 'Go for a break!'
|
text = 'Go for a break!'
|
||||||
else:
|
else:
|
||||||
self.state = 'running'
|
self.state = 'running'
|
||||||
self.time = datetime.now() + \
|
self.time = datetime.utcnow() + \
|
||||||
timedelta(seconds=self.pomodoro_duration)
|
timedelta(seconds=self.pomodoro_duration)
|
||||||
text = 'Back to work!'
|
text = 'Back to work!'
|
||||||
self._alarm(text)
|
self._alarm(text)
|
||||||
|
|
||||||
if self.state == 'running' or self.state == 'break':
|
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))
|
text = '{:02}:{:02}'.format(int(min), int(sec))
|
||||||
color = self.color_running if self.state == 'running' else self.color_break
|
color = self.color_running if self.state == 'running' else self.color_break
|
||||||
else:
|
else:
|
||||||
@ -82,7 +81,7 @@ class Pomodoro(IntervalModule):
|
|||||||
|
|
||||||
sdict = {
|
sdict = {
|
||||||
'time': text,
|
'time': text,
|
||||||
'current_pomodoro': self.breaks,
|
'current_pomodoro': self.breaks + 1,
|
||||||
'total_pomodoro': self.short_break_count + 1,
|
'total_pomodoro': self.short_break_count + 1,
|
||||||
}
|
}
|
||||||
self.data = sdict
|
self.data = sdict
|
||||||
@ -93,7 +92,7 @@ class Pomodoro(IntervalModule):
|
|||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.state = 'running'
|
self.state = 'running'
|
||||||
self.time = datetime.now() + timedelta(seconds=self.pomodoro_duration)
|
self.time = datetime.utcnow() + timedelta(seconds=self.pomodoro_duration)
|
||||||
self.breaks = 0
|
self.breaks = 0
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user