|
14 | 14 | from requests_oauthlib import OAuth2Session |
15 | 15 | from stringcase import pascalcase, camelcase, snakecase |
16 | 16 | from tzlocal import get_localzone |
17 | | -from zoneinfo import ZoneInfoNotFoundError |
| 17 | +from zoneinfo import ZoneInfoNotFoundError, ZoneInfo |
18 | 18 | from .utils import ME_RESOURCE, BaseTokenBackend, FileSystemTokenBackend, Token |
19 | 19 | import datetime as dt |
20 | 20 |
|
@@ -96,13 +96,19 @@ def __init__(self, *, protocol_url=None, api_version=None, |
96 | 96 | self.default_resource = default_resource or ME_RESOURCE |
97 | 97 | self.use_default_casing = True if casing_function is None else False |
98 | 98 | self.casing_function = casing_function or camelcase |
99 | | - if timezone and isinstance(timezone, str): |
100 | | - timezone = dt.timezone(timezone) |
101 | | - try: |
102 | | - self.timezone = timezone or get_localzone() |
103 | | - except ZoneInfoNotFoundError as e: |
104 | | - log.debug('Timezone not provided and the local timezone could not be found. Default to UTC.') |
105 | | - self.timezone = dt.timezone.utc |
| 99 | + if timezone: |
| 100 | + if isinstance(timezone, str): |
| 101 | + # convert string to ZoneInfo |
| 102 | + try: |
| 103 | + timezone = ZoneInfo(timezone) |
| 104 | + except ZoneInfoNotFoundError: |
| 105 | + log.debug(f'Timezone {timezone} could not be found. Will default to UTC.') |
| 106 | + timezone = ZoneInfo('UTC') |
| 107 | + else: |
| 108 | + if not isinstance(timezone, ZoneInfo): |
| 109 | + raise ValueError(f'The timezone parameter must be either a string or a valid ZoneInfo instance.') |
| 110 | + # get_localzone() from tzlocal will try to get the system local timezone and if not will return UTC |
| 111 | + self.timezone = timezone or get_localzone() |
106 | 112 | self.max_top_value = 500 # Max $top parameter value |
107 | 113 |
|
108 | 114 | # define any keyword that can be different in this protocol |
|
0 commit comments