@@ -68,27 +68,47 @@ class UTC(datetime.tzinfo):
68
68
"""
69
69
70
70
@property
71
- def _utcoffset (self ):
71
+ def _utcoffset (self ) -> datetime . timedelta :
72
72
"""Helps make this work with pytz."""
73
73
return datetime .timedelta (0 )
74
74
75
- def utcoffset (self , stamp ):
75
+ def utcoffset (self , stamp ) -> datetime . timedelta :
76
76
return datetime .timedelta (0 )
77
77
78
- def tzname (self , stamp ):
78
+ def tzname (self , stamp ) -> str :
79
79
return "UTC"
80
80
81
- def dst (self , stamp ):
81
+ def dst (self , stamp ) -> datetime . timedelta :
82
82
return datetime .timedelta (0 )
83
83
84
- def __repr__ (self ):
84
+ def __repr__ (self ) -> str :
85
85
return "UTC()"
86
86
87
- def __reduce__ (self ):
87
+ def __reduce__ (self ) -> tuple :
88
88
# This method makes the UTC object pickleable
89
89
return UTC , ()
90
90
91
91
92
+ def utc (
93
+ year , month , day , hour = 0 , minute = 0 , second = 0 , microsecond = 0
94
+ ) -> datetime .datetime :
95
+ """Return a timezone-aware datetime object for the given UTC time.
96
+
97
+ :param int year: Year
98
+ :param int month: Month
99
+ :param int day: Day
100
+ :param int hour: Hour (default: ``0``)
101
+ :param int minute: Minute (default: ``0``)
102
+ :param int second: Second (default: ``0``)
103
+ :param int microsecond: Microsecond (default: ``0``)
104
+ :returns: UTC datetime object
105
+
106
+ """
107
+ return datetime .datetime (
108
+ year , month , day , hour , minute , second , microsecond , tzinfo = UTC ()
109
+ )
110
+
111
+
92
112
def is_dst (stamp ):
93
113
"""Return ``True`` if `stamp` is daylight savings.
94
114
@@ -99,7 +119,7 @@ def is_dst(stamp):
99
119
return time .localtime (time .mktime (stamp .timetuple ())).tm_isdst == 1
100
120
101
121
102
- def utcnow ():
122
+ def utcnow () -> datetime . datetime :
103
123
"""Return the current UTC time as a timezone-aware datetime.
104
124
105
125
:returns: The current UTC time
@@ -108,7 +128,7 @@ def utcnow():
108
128
return datetime .datetime .now (UTC ())
109
129
110
130
111
- def fromutctimestamp (stamp ):
131
+ def fromutctimestamp (stamp ) -> datetime . datetime :
112
132
"""Return a timezone-aware datetime object from a UTC unix timestamp.
113
133
114
134
:param float stamp: Unix timestamp in UTC
@@ -131,7 +151,7 @@ def fromutctimestamp(stamp):
131
151
return new_stamp
132
152
133
153
134
- def toutctimestamp (stamp ):
154
+ def toutctimestamp (stamp ) -> datetime . datetime :
135
155
"""Converts a naive datetime object to a UTC unix timestamp. This has an
136
156
advantage over `time.mktime` in that it preserves the decimal portion
137
157
of the timestamp when converting.
@@ -156,7 +176,7 @@ def toutctimestamp(stamp):
156
176
return time .mktime (stamp .timetuple ()) + decimal
157
177
158
178
159
- def as_utc (stamp ):
179
+ def as_utc (stamp ) -> datetime . datetime :
160
180
"""Converts any datetime (naive or aware) to UTC time.
161
181
162
182
:param datetime stamp: Datetime to convert
@@ -173,7 +193,7 @@ def as_utc(stamp):
173
193
return fromutctimestamp (toutctimestamp (stamp ))
174
194
175
195
176
- def trim_time (stamp ):
196
+ def trim_time (stamp ) -> datetime . datetime :
177
197
"""Trims the time portion off of `stamp`, leaving the date intact.
178
198
Returns a datetime of the same date, set to 00:00:00 hours. Preserves
179
199
timezone information.
@@ -185,7 +205,7 @@ def trim_time(stamp):
185
205
return datetime .datetime (* stamp .date ().timetuple ()[:- 3 ], tzinfo = stamp .tzinfo )
186
206
187
207
188
- def week_start (stamp ):
208
+ def week_start (stamp ) -> datetime . datetime :
189
209
"""Return the start of the week containing `stamp`.
190
210
191
211
.. versionchanged:: 2.0
@@ -200,7 +220,7 @@ def week_start(stamp):
200
220
return stamp
201
221
202
222
203
- def week_seconds (stamp ):
223
+ def week_seconds (stamp ) -> int :
204
224
"""Return `stamp` converted to seconds since 00:00 Monday.
205
225
206
226
:param datetime stamp: Timestamp to convert
@@ -211,7 +231,7 @@ def week_seconds(stamp):
211
231
return int (difference .total_seconds ())
212
232
213
233
214
- def week_seconds_to_datetime (seconds ):
234
+ def week_seconds_to_datetime (seconds ) -> datetime . datetime :
215
235
"""Return the datetime that is `seconds` from the start of this week.
216
236
217
237
:param int seconds: Seconds
@@ -221,7 +241,7 @@ def week_seconds_to_datetime(seconds):
221
241
return week_start (datetime .datetime .now ()) + datetime .timedelta (seconds = seconds )
222
242
223
243
224
- def make_week_seconds (day , hour , minute = 0 , seconds = 0 ):
244
+ def make_week_seconds (day , hour , minute = 0 , seconds = 0 ) -> int :
225
245
"""Return :func:`week_seconds` for the given `day` of the week, `hour`
226
246
and `minute`.
227
247
@@ -240,7 +260,7 @@ def make_week_seconds(day, hour, minute=0, seconds=0):
240
260
return week_seconds (stamp )
241
261
242
262
243
- def floor_minute (stamp = None ):
263
+ def floor_minute (stamp = None ) -> datetime . datetime :
244
264
"""Return `stamp` floored to the current minute. If no `stamp` is
245
265
specified, the current time is used. Preserves timezone information.
246
266
0 commit comments