forked from charlesmadere/CynanBotCommon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeZoneRepository.py
41 lines (28 loc) · 1.07 KB
/
timeZoneRepository.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from typing import List
import pytz
import CynanBotCommon.utils as utils
# A listing of pytz timezones can be found here:
# https://stackoverflow.com/questions/13866926/is-there-a-list-of-pytz-timezones
class TimeZoneRepository():
def __init__(self):
self.__timeZones = dict()
def getTimeZone(self, timeZone: str):
if not utils.isValidStr(timeZone):
return None
elif timeZone in self.__timeZones:
return self.__timeZones[timeZone]
newTimeZone = pytz.timezone(timeZone)
self.__timeZones[timeZone] = newTimeZone
return newTimeZone
def getTimeZones(self, timeZones: List[str]):
if not utils.hasItems(timeZones):
return None
newTimeZones = list()
for timeZone in timeZones:
newTimeZone = self.getTimeZone(timeZone)
if newTimeZone is not None:
newTimeZones.append(newTimeZone)
if utils.hasItems(newTimeZones):
return newTimeZones
else:
return None