Show More
@@ -1,48 +1,52 | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | """ |
|
3 | 3 | Timezone utilities |
|
4 | 4 | |
|
5 | 5 | Just UTC-awareness right now |
|
6 | 6 | """ |
|
7 | 7 | |
|
8 | 8 | #----------------------------------------------------------------------------- |
|
9 | 9 | # Copyright (C) 2013 The IPython Development Team |
|
10 | 10 | # |
|
11 | 11 | # Distributed under the terms of the BSD License. The full license is in |
|
12 | 12 | # the file COPYING, distributed as part of this software. |
|
13 | 13 | #----------------------------------------------------------------------------- |
|
14 | 14 | |
|
15 | 15 | #----------------------------------------------------------------------------- |
|
16 | 16 | # Imports |
|
17 | 17 | #----------------------------------------------------------------------------- |
|
18 | 18 | |
|
19 | 19 | from datetime import tzinfo, timedelta, datetime |
|
20 | 20 | |
|
21 | 21 | #----------------------------------------------------------------------------- |
|
22 | 22 | # Code |
|
23 | 23 | #----------------------------------------------------------------------------- |
|
24 | 24 | # constant for zero offset |
|
25 | 25 | ZERO = timedelta(0) |
|
26 | 26 | |
|
27 | ||
|
27 | 28 | class tzUTC(tzinfo): |
|
28 | 29 | """tzinfo object for UTC (zero offset)""" |
|
29 | 30 | |
|
30 | 31 | def utcoffset(self, d): |
|
31 | 32 | return ZERO |
|
32 | 33 | |
|
33 | 34 | def dst(self, d): |
|
34 | 35 | return ZERO |
|
35 | 36 | |
|
36 | 37 | |
|
37 | 38 | UTC = tzUTC() # type: ignore[abstract] |
|
38 | 39 | |
|
39 | 40 | |
|
40 | 41 | def utc_aware(unaware): |
|
41 | 42 | """decorator for adding UTC tzinfo to datetime's utcfoo methods""" |
|
43 | ||
|
42 | 44 | def utc_method(*args, **kwargs): |
|
43 | 45 | dt = unaware(*args, **kwargs) |
|
44 | 46 | return dt.replace(tzinfo=UTC) |
|
47 | ||
|
45 | 48 | return utc_method |
|
46 | 49 | |
|
50 | ||
|
47 | 51 | utcfromtimestamp = utc_aware(datetime.utcfromtimestamp) |
|
48 | 52 | utcnow = utc_aware(datetime.utcnow) |
General Comments 0
You need to be logged in to leave comments.
Login now