##// END OF EJS Templates
Add deprecation docstrings and warning.
Nils Müller -
Show More
@@ -1,52 +1,75 b''
1 # encoding: utf-8
1 # encoding: utf-8
2 """
2 """
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
28 __all__ = ["tzUTC", "utc_aware", "utcfromtimestamp", "utcnow"]
29
24 # constant for zero offset
30 # constant for zero offset
25 ZERO = timedelta(0)
31 ZERO = timedelta(0)
26
32
27
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 msg = "The module `IPython.utils.tz` is deprecated and will be completely removed."
40 warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
41
42 return getattr(name)
43
44
28 class tzUTC(tzinfo):
45 class tzUTC(tzinfo):
29 """tzinfo object for UTC (zero offset)"""
46 """tzinfo object for UTC (zero offset)
47
48 Deprecated since IPython 8.19.0.
49 """
30
50
31 def utcoffset(self, d):
51 def utcoffset(self, d):
32 return ZERO
52 return ZERO
33
53
34 def dst(self, d):
54 def dst(self, d):
35 return ZERO
55 return ZERO
36
56
37
57
38 UTC = tzUTC() # type: ignore[abstract]
58 UTC = tzUTC() # type: ignore[abstract]
39
59
40
60
41 def utc_aware(unaware):
61 def utc_aware(unaware):
42 """decorator for adding UTC tzinfo to datetime's utcfoo methods"""
62 """decorator for adding UTC tzinfo to datetime's utcfoo methods
63
64 Deprecated since IPython 8.19.0.
65 """
43
66
44 def utc_method(*args, **kwargs):
67 def utc_method(*args, **kwargs):
45 dt = unaware(*args, **kwargs)
68 dt = unaware(*args, **kwargs)
46 return dt.replace(tzinfo=UTC)
69 return dt.replace(tzinfo=UTC)
47
70
48 return utc_method
71 return utc_method
49
72
50
73
51 utcfromtimestamp = utc_aware(datetime.utcfromtimestamp)
74 utcfromtimestamp = utc_aware(datetime.utcfromtimestamp)
52 utcnow = utc_aware(datetime.utcnow)
75 utcnow = utc_aware(datetime.utcnow)
General Comments 0
You need to be logged in to leave comments. Login now