1 # encoding: utf-8 2 """ 3 Timezone utilities 4 5 Just UTC-awareness right now 6 7 Deprecated since IPython 8.19.0. 8 """ 9 10 # ----------------------------------------------------------------------------- 11 # Copyright (C) 2013 The IPython Development Team 12 # 13 # Distributed under the terms of the BSD License. The full license is in 14 # the file COPYING, distributed as part of this software. 15 # ----------------------------------------------------------------------------- 16 17 # ----------------------------------------------------------------------------- 18 # Imports 19 # ----------------------------------------------------------------------------- 20 21 import warnings 22 from datetime import tzinfo, timedelta, datetime 23 24 # ----------------------------------------------------------------------------- 25 # Code 26 # ----------------------------------------------------------------------------- 27 __all__ = ["tzUTC", "utc_aware", "utcfromtimestamp", "utcnow"] 28 29 30 # constant for zero offset 31 ZERO = timedelta(0) 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 49 class tzUTC(tzinfo): 50 """tzinfo object for UTC (zero offset) 51 52 Deprecated since IPython 8.19.0. 53 """ 54 55 _warn_deprecated() 56 57 def utcoffset(self, d): 58 return ZERO 59 60 def dst(self, d): 61 return ZERO 62 63 64 UTC = tzUTC() # type: ignore[abstract] 65 66 67 def utc_aware(unaware): 68 """decorator for adding UTC tzinfo to datetime's utcfoo methods 69 70 Deprecated since IPython 8.19.0. 71 """ 72 73 def utc_method(*args, **kwargs): 74 _warn_deprecated() 75 dt = unaware(*args, **kwargs) 76 return dt.replace(tzinfo=UTC) 77 78 return utc_method 79 80 81 utcfromtimestamp = utc_aware(datetime.utcfromtimestamp) 82 utcnow = utc_aware(datetime.utcnow) 83