##// END OF EJS Templates
Add deprecation docstrings and warning.
Nils Müller -
Show More
@@ -1,52 +1,75 b''
1 1 # encoding: utf-8
2 2 """
3 3 Timezone utilities
4 4
5 5 Just UTC-awareness right now
6
7 Deprecated since IPython 8.19.0.
6 8 """
7 9
8 10 # -----------------------------------------------------------------------------
9 11 # Copyright (C) 2013 The IPython Development Team
10 12 #
11 13 # Distributed under the terms of the BSD License. The full license is in
12 14 # the file COPYING, distributed as part of this software.
13 15 # -----------------------------------------------------------------------------
14 16
15 17 # -----------------------------------------------------------------------------
16 18 # Imports
17 19 # -----------------------------------------------------------------------------
18 20
21 import warnings
19 22 from datetime import tzinfo, timedelta, datetime
20 23
21 24 # -----------------------------------------------------------------------------
22 25 # Code
23 26 # -----------------------------------------------------------------------------
27
28 __all__ = ["tzUTC", "utc_aware", "utcfromtimestamp", "utcnow"]
29
24 30 # constant for zero offset
25 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 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 51 def utcoffset(self, d):
32 52 return ZERO
33 53
34 54 def dst(self, d):
35 55 return ZERO
36 56
37 57
38 58 UTC = tzUTC() # type: ignore[abstract]
39 59
40 60
41 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 67 def utc_method(*args, **kwargs):
45 68 dt = unaware(*args, **kwargs)
46 69 return dt.replace(tzinfo=UTC)
47 70
48 71 return utc_method
49 72
50 73
51 74 utcfromtimestamp = utc_aware(datetime.utcfromtimestamp)
52 75 utcnow = utc_aware(datetime.utcnow)
General Comments 0
You need to be logged in to leave comments. Login now