Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def exchange_tz(self, exchange, exchanges=None):
# NOTE(jkoelker) EODData's service is windows based, convert times here
if exchanges is None:
exchanges = self.exchanges()
exchange_tz = exchanges[exchange]['time_zone']
return pytz.timezone(windows_tz.tz_names[exchange_tz])
if WindowsZoneName is True, then it returns the name used by the Microsoft Windows Platform
otherwise it returns the Olsen name (used by all other platforms)
Note: this needs to get tested on Windows
"""
log = logging.getLogger(__name__)
localzone = tzlocal.get_localzone()
if localzone is None:
log.error('tzlocal did not provide a time zone configuration')
raise pytz.UnknownTimeZoneError('Cannot find any time zone configuration')
else:
olsen_name = localzone.zone
if WindowsZoneName:
try:
windows_name = tzlocal.windows_tz.tz_win[olsen_name]
log.info('Mappped Olsen Time Zone Name (' + olsen_name + ') to Windows Time Zone Name (' + windows_name + ')')
return windows_name
except LookupError:
log.error('Unable to map Olsen Time Zone Name (' + olsen_name + ') to Windows Time Zone Name')
return 'Unknown'
else:
return olsen_name
def set_timezone(self, timezone_name):
windows_name = windows_tz.tz_win.get(timezone_name)
if not windows_name:
raise exception.CloudbaseInitException(
"The given timezone name is unrecognised: %r" % timezone_name)
timezone.Timezone(windows_name).set(self)