from pi3bar.plugins.base import Plugin
import datetime


class Clock(Plugin):
    """
    :class:`pi3bar.app.Pi3Bar` plugin to show the current date and time.

    :param full_format: :class:`str` - :meth:`datetime.datetime.strftime` argument
    :param short_format: :class:`str` - :meth:`datetime.datetime.strftime` argument, short alternative
    :param timezone: :class:`str` - timezone to use. E.g. 'US/Pacific' or 'Europe/Berlin'

    Examples:

    .. code-block:: python

        # default formats:
        Clock(full_format='%Y-%m-%d %H:%M:%S', short_format='%d. %H:%M:%S')

        #
        Clock(full_format='%d.%m.%Y %H:%M:%S'),  # other format example

        # pass a timezone
        Clock(timezone='US/Eastern')
    """

    #: Refresh every second
    ticks = 1

    def __init__(self, full_format='%Y-%m-%d %H:%M:%S', short_format='%d. %H:%M', timezone=None, **kwargs):
        self.full_format = full_format
        self.short_format = short_format
        self.timezone = timezone
        self.instance = timezone
        super(Clock, self).__init__(**kwargs)

    def cycle(self):
        now = datetime.datetime.now(self.timezone)
        self.full_text = now.strftime(self.full_format)
        self.short_text = now.strftime(self.short_format)
