32
32
33
33
# stdlib
34
34
import datetime
35
+ import sys
36
+ import typing
35
37
from collections import OrderedDict
36
38
from typing import Optional , Union
37
39
@@ -110,8 +112,6 @@ def get_timezone(tz: str, date: Optional[datetime.datetime] = None) -> Optional[
110
112
def current_tzinfo () -> Optional [datetime .tzinfo ]:
111
113
"""
112
114
Returns a tzinfo object for the current timezone.
113
-
114
- :rtype: :class:`python:datetime.tzinfo`
115
115
"""
116
116
117
117
return datetime .datetime .now ().astimezone ().tzinfo # pragma: no cover (hard to test)
@@ -126,7 +126,7 @@ def current_tzinfo() -> Optional[datetime.tzinfo]:
126
126
# :type datetime: :class:`datetime.datetime`
127
127
# :param current_tzinfo: A tzinfo object representing the current timezone.
128
128
# If None it will be inferred.
129
- # :type current_tzinfo: :class:`~python: datetime.tzinfo`
129
+ # :type current_tzinfo: :class:`datetime.tzinfo`
130
130
#
131
131
# :return: Timestamp in UTC timezone
132
132
# :rtype: float
@@ -140,12 +140,10 @@ def set_timezone(obj: datetime.datetime, tzinfo: datetime.tzinfo) -> datetime.da
140
140
"""
141
141
Sets the timezone / tzinfo of the given :class:`datetime.datetime` object.
142
142
This will not convert the time (i.e. the hours will stay the same).
143
- Use :meth:`python: datetime.datetime.astimezone` to accomplish that.
143
+ Use :meth:`datetime.datetime.astimezone` to accomplish that.
144
144
145
145
:param obj:
146
146
:param tzinfo:
147
-
148
- :return:
149
147
"""
150
148
151
149
return obj .replace (tzinfo = tzinfo )
@@ -161,7 +159,7 @@ def utc_timestamp_to_datetime(
161
159
If ``output_tz`` is None the timestamp is converted to the platform’s local date and time,
162
160
and the local timezone is inferred and set for the object.
163
161
164
- If ``output_tz`` is not None, it must be an instance of a :class:`~python: datetime.tzinfo` subclass,
162
+ If ``output_tz`` is not None, it must be an instance of a :class:`datetime.tzinfo` subclass,
165
163
and the timestamp is converted to ``output_tz``’s time zone.
166
164
167
165
@@ -171,7 +169,7 @@ def utc_timestamp_to_datetime(
171
169
172
170
:return: The timestamp as a datetime object.
173
171
174
- :raises: :class:`~python: OverflowError` if the timestamp is out of the range
172
+ :raises OverflowError: if the timestamp is out of the range
175
173
of values supported by the platform C localtime() or gmtime() functions,
176
174
and OSError on localtime() or gmtime() failure. It’s common for this to
177
175
be restricted to years in 1970 through 2038.
@@ -181,8 +179,13 @@ def utc_timestamp_to_datetime(
181
179
return new_datetime .astimezone (output_tz )
182
180
183
181
184
- # Mapping of months to their 3-character shortcodes.
185
- months = OrderedDict (
182
+ if sys .version_info <= (3 , 7 ):
183
+ MonthsType = OrderedDict
184
+ else :
185
+ MonthsType = typing .OrderedDict [str , str ]
186
+
187
+ #: Mapping of 3-character shortcodes to full month names.
188
+ months : MonthsType = OrderedDict (
186
189
Jan = "January" ,
187
190
Feb = "February" ,
188
191
Mar = "March" ,
0 commit comments