Coverage for cmds/time.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

13 statements  

1""" 

2time.py 

3 

4contains time() 

5""" 

6 

7import datetime 

8import pytz 

9 

10import error 

11 

12 

13async def time(*args): 

14 """ 

15 time() 

16 

17 returns time at timezone 

18 """ 

19 

20 # fix args 

21 args = args[1:] 

22 

23 # checks for excess arguments 

24 if len(args) > 1: 

25 raise error.UnknownArgumentError 

26 

27 # checks for argument 

28 if len(args) == 1: 

29 

30 # checks timezone 

31 if args[0] not in pytz.all_timezones: 

32 raise error.TimezoneNotFoundError 

33 

34 # sets timezone 

35 timezone = args[0] 

36 

37 else: 

38 # sets default timezone 

39 timezone = 'UTC' 

40 

41 # returns output 

42 return datetime.datetime.now(pytz.timezone(timezone)).strftime("%A %Y %B %d %H:%M:%S %Z %z")