Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1import datetime 

2from pi3bar.plugins.base import Plugin 

3 

4 

5class Clock(Plugin): 

6 """ 

7 :class:`pi3bar.app.Pi3Bar` plugin to show the current date and time. 

8 

9 :param full_format: :class:`str` - :meth:`datetime.datetime.strftime` argument 

10 :param short_format: :class:`str` - :meth:`datetime.datetime.strftime` argument, short alternative 

11 :param timezone: :class:`str` - timezone to use. E.g. 'US/Pacific' or 'Europe/Berlin' 

12 

13 Examples: 

14 

15 .. code-block:: python 

16 

17 # default formats: 

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

19 

20 # 

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

22 

23 # pass a timezone 

24 Clock(timezone='US/Eastern') 

25 """ 

26 

27 #: Refresh every second 

28 ticks = 1 

29 

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

31 self.full_format = full_format 

32 self.short_format = short_format 

33 self.timezone = timezone 

34 self.instance = timezone 

35 super(Clock, self).__init__(**kwargs) 

36 

37 def cycle(self): 

38 now = datetime.datetime.now(self.timezone) 

39 self.full_text = now.strftime(self.full_format) 

40 self.short_text = now.strftime(self.short_format)