From aa9941ceda96533d8e299a37d21750be73047c9b Mon Sep 17 00:00:00 2001 From: Naya Verdier Date: Sun, 6 Aug 2017 11:29:41 -0700 Subject: [PATCH] [module/datetime] Add locale parameter to override system default This change mostly affects the %x and %X variables, for example to change to 24 hour time you might set the locale to 'en_UK.UTF-8'. --- bumblebee/modules/datetime.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/bumblebee/modules/datetime.py b/bumblebee/modules/datetime.py index e1b9236..64df23e 100644 --- a/bumblebee/modules/datetime.py +++ b/bumblebee/modules/datetime.py @@ -6,6 +6,9 @@ Parameters: * datetime.format: strftime()-compatible formatting string * date.format : alias for datetime.format * time.format : alias for datetime.format + * datetime.locale: locale to use rather than the system default + * date.locale : alias for datetime.locale + * time.locale : alias for datetime.locale """ from __future__ import absolute_import @@ -13,8 +16,6 @@ import datetime import locale import bumblebee.engine -locale.setlocale(locale.LC_TIME, locale.getdefaultlocale()) - ALIASES = [ "date", "time" ] def default_format(module): @@ -28,9 +29,15 @@ def default_format(module): class Module(bumblebee.engine.Module): def __init__(self, engine, config): super(Module, self).__init__(engine, config, - bumblebee.output.Widget(full_text=self.get_time) - ) + bumblebee.output.Widget(full_text=self.get_time)) self._fmt = self.parameter("format", default_format(self.name)) + self._lcl = self.parameter("locale").split(".") + + # can't use the default in "parameter" because we split the + # string, while 'getdefaultlocale' already returns a tuple + if self._lcl is None: + self._lcl = locale.getdefaultlocale() + locale.setlocale(locale.LC_TIME, self._lcl) def get_time(self, widget): return datetime.datetime.now().strftime(self._fmt)