# pylint: disable=C0111,R0903

"""Displays the current date and time.

Parameters:
    * datetime.format: strftime()-compatible formatting string
    * date.format    : alias for datetime.format
    * time.format    : alias for datetime.format
"""

from __future__ import absolute_import
import datetime
import locale
import bumblebee.engine

locale.setlocale(locale.LC_TIME, locale.getdefaultlocale())

ALIASES = [ "date", "time" ]

def default_format(module):
    default = "%x %X"
    if module == "date":
        default = "%x"
    if module == "time":
        default = "%X"
    return default

class Module(bumblebee.engine.Module):
    def __init__(self, engine, config):
        super(Module, self).__init__(engine, config,
            bumblebee.output.Widget(full_text=self.get_time)
        )
        self._fmt = self.parameter("format", default_format(self.name))

    def get_time(self, widget):
        return datetime.datetime.now().strftime(self._fmt)

# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

@@ -237,16 +237,182 @@
 .format%0A
+    * datetime.locale: locale to use rather than the system default%0A    * date.locale    : alias for datetime.locale%0A    * time.locale    : alias for datetime.locale%0A
 %22%22%22%0A%0Afro
@@ -506,69 +506,8 @@
 ne%0A%0A
-locale.setlocale(locale.LC_TIME, locale.getdefaultlocale())%0A%0A
 ALIA
@@ -890,25 +890,16 @@
 et_time)
-%0A        
 )%0A      
@@ -963,16 +963,340 @@
 f.name))
+%0A        self._lcl = self.parameter(%22locale%22).split(%22.%22)%0A%0A        # can't use the default in %22parameter%22 because we split the%0A        # string, while 'getdefaultlocale' already returns a tuple%0A        if self._lcl is None:%0A            self._lcl = locale.getdefaultlocale()%0A        locale.setlocale(locale.LC_TIME, self._lcl)
 %0A%0A    de

Add locale parameter to override system default