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