Skip to content

Commit

Permalink
Use datetime.now() instead of datetime.fromtimestamp()
Browse files Browse the repository at this point in the history
The datetime object has a neat .now() method the calculates the current
time.  This pull-request uses datetime.now() instead of a call to time()
and a call to datetime.fromtimestamp().  Merging this will close #718.

Closes #721
  • Loading branch information
kseistrup authored and flacjacket committed Jul 23, 2015
1 parent 35c22fa commit 1cefc80
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -3,6 +3,7 @@ qtile 0.x.x, released xxxx-xx-xx:
- improved serialization of layouts across restarts
- cmd_togroup can move to current group when None sent
* bugfixes
- Clock widget uses datetime.now() rather than .fromtimestamp()
- fix Python 3 compatibility of ThermalSensor widget
- various Systray fixes, including implementing XEMBED protocol
- print exception to log during loading config
Expand Down
17 changes: 8 additions & 9 deletions libqtile/widget/clock.py
Expand Up @@ -22,7 +22,7 @@
# SOFTWARE.

from time import time
from datetime import datetime
from datetime import datetime, timedelta
from contextlib import contextmanager
from . import base

Expand Down Expand Up @@ -50,21 +50,20 @@ class Clock(base.InLoopPollText):
'e.g. "US/Central" (or anything in /usr/share/zoneinfo). None means '
'the default timezone.')
]
DELTA = timedelta(seconds=0.5)

def __init__(self, **config):
base.InLoopPollText.__init__(self, **config)
self.add_defaults(Clock.defaults)

def tick(self):
self.update(self.poll())
ts = time()
return self.update_interval - ts % self.update_interval
return self.update_interval - time() % self.update_interval

def _get_time(self):
ts = time()
# adding .5 to get a proper seconds value because glib could
# theoreticaly call our method too early and we could get something
# like (x-1).999 instead of x.000
return datetime.fromtimestamp(int(ts + .5)).strftime(self.format)
# adding .5 to get a proper seconds value because glib could
# theoreticaly call our method too early and we could get something
# like (x-1).999 instead of x.000
_get_time = lambda self: (datetime.now() + self.DELTA).strftime(self.format)

def poll(self):
# We use None as a sentinel here because C's strftime defaults to UTC
Expand Down

0 comments on commit 1cefc80

Please sign in to comment.