diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-08-31 19:37:08 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-08-31 19:37:08 +0200 |
commit | 5fc328ec0545c1183b0a2bcb26196fbd06b2be95 (patch) | |
tree | 04e0941340ccf95f7a51930daba6476b9ccb5849 /src/plugins/clock.py | |
parent | use the devfs method by default in Users (diff) | |
download | xpybar-5fc328ec0545c1183b0a2bcb26196fbd06b2be95.tar.gz xpybar-5fc328ec0545c1183b0a2bcb26196fbd06b2be95.tar.bz2 xpybar-5fc328ec0545c1183b0a2bcb26196fbd06b2be95.tar.xz |
do not spawn new processes all the time
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/plugins/clock.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/plugins/clock.py b/src/plugins/clock.py index 129269c..fc99ca4 100644 --- a/src/plugins/clock.py +++ b/src/plugins/clock.py @@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ''' import time +from datetime import datetime, timezone from util import * @@ -47,10 +48,9 @@ class Clock: @param utc:bool Show time in UTC, otherwise local time @param sync_to:float The time parameter to sync to, the number of seconds between the reads ''' - self.format = format + self.format = format if not utc else format.replace('%Z', 'UTC') self.utc = utc self.sync_to = sync_to - self.command = ['date'] + (['--utc'] if utc else []) + ['+' + format] def read(self): @@ -59,7 +59,10 @@ class Clock: @return :str The time and date in the format specified at construction ''' - return spawn_read(*(self.command)) + if not self.utc: + return time.strftime(self.format) + else: + datetime.fromtimestamp(time.time(), tz = timezone.utc).strftime(self.format)) def sync(self): |