Show More
@@ -1,75 +1,84 b'' | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | """ |
|
3 | 3 | Timezone utilities |
|
4 | 4 | |
|
5 | 5 | Just UTC-awareness right now |
|
6 | 6 | |
|
7 | 7 | Deprecated since IPython 8.19.0. |
|
8 | 8 | """ |
|
9 | 9 | |
|
10 | 10 | # ----------------------------------------------------------------------------- |
|
11 | 11 | # Copyright (C) 2013 The IPython Development Team |
|
12 | 12 | # |
|
13 | 13 | # Distributed under the terms of the BSD License. The full license is in |
|
14 | 14 | # the file COPYING, distributed as part of this software. |
|
15 | 15 | # ----------------------------------------------------------------------------- |
|
16 | 16 | |
|
17 | 17 | # ----------------------------------------------------------------------------- |
|
18 | 18 | # Imports |
|
19 | 19 | # ----------------------------------------------------------------------------- |
|
20 | 20 | |
|
21 | 21 | import warnings |
|
22 | 22 | from datetime import tzinfo, timedelta, datetime |
|
23 | 23 | |
|
24 | 24 | # ----------------------------------------------------------------------------- |
|
25 | 25 | # Code |
|
26 | 26 | # ----------------------------------------------------------------------------- |
|
27 | ||
|
28 | 27 | __all__ = ["tzUTC", "utc_aware", "utcfromtimestamp", "utcnow"] |
|
29 | 28 | |
|
29 | # Enable display of DeprecrationWarning for this module explicitly. | |
|
30 | warnings.filterwarnings("default", category=DeprecationWarning, module=__name__) | |
|
31 | ||
|
30 | 32 | # constant for zero offset |
|
31 | 33 | ZERO = timedelta(0) |
|
32 | 34 | |
|
33 | 35 | |
|
34 | 36 | def __getattr__(name): |
|
35 | 37 | if name not in __all__: |
|
36 | 38 | err = f"IPython.utils.tz is deprecated and has no attribute {name}" |
|
37 | 39 | raise AttributeError(err) |
|
38 | 40 | |
|
39 | msg = "The module `IPython.utils.tz` is deprecated and will be completely removed." | |
|
40 | warnings.warn(msg, category=DeprecationWarning, stacklevel=2) | |
|
41 | _warn_deprecated() | |
|
41 | 42 | |
|
42 | 43 | return getattr(name) |
|
43 | 44 | |
|
44 | 45 | |
|
46 | def _warn_deprecated(): | |
|
47 | msg = "The module `IPython.utils.tz` is deprecated and will be completely removed." | |
|
48 | warnings.warn(msg, category=DeprecationWarning, stacklevel=2) | |
|
49 | ||
|
50 | ||
|
45 | 51 | class tzUTC(tzinfo): |
|
46 | 52 | """tzinfo object for UTC (zero offset) |
|
47 | 53 | |
|
48 | 54 | Deprecated since IPython 8.19.0. |
|
49 | 55 | """ |
|
50 | 56 | |
|
57 | _warn_deprecated() | |
|
58 | ||
|
51 | 59 | def utcoffset(self, d): |
|
52 | 60 | return ZERO |
|
53 | 61 | |
|
54 | 62 | def dst(self, d): |
|
55 | 63 | return ZERO |
|
56 | 64 | |
|
57 | 65 | |
|
58 | 66 | UTC = tzUTC() # type: ignore[abstract] |
|
59 | 67 | |
|
60 | 68 | |
|
61 | 69 | def utc_aware(unaware): |
|
62 | 70 | """decorator for adding UTC tzinfo to datetime's utcfoo methods |
|
63 | 71 | |
|
64 | 72 | Deprecated since IPython 8.19.0. |
|
65 | 73 | """ |
|
66 | 74 | |
|
67 | 75 | def utc_method(*args, **kwargs): |
|
76 | _warn_deprecated() | |
|
68 | 77 | dt = unaware(*args, **kwargs) |
|
69 | 78 | return dt.replace(tzinfo=UTC) |
|
70 | 79 | |
|
71 | 80 | return utc_method |
|
72 | 81 | |
|
73 | 82 | |
|
74 | 83 | utcfromtimestamp = utc_aware(datetime.utcfromtimestamp) |
|
75 | 84 | utcnow = utc_aware(datetime.utcnow) |
General Comments 0
You need to be logged in to leave comments.
Login now