From 4e01f29bafc75ef7c9ecc14cb7df25c6ba5c76cf Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 20 Jan 2015 12:04:58 +0100 Subject: Deprecate strtime This patches deprecated strtime() as it's a either useless or a very bad idea to use it. It's useless because it's a 3 lines wrapper around utcnow(), datetime.strftime() and isotime() so does not bring anything useful as it can be replaced by one line of code in all cases. It's a bad idea because contrary to what one could expect: strtime() != isotime(subsecond=True) strtime(dt) != isotime(dt, subsecond=True) Also, it does not include any timezone information so it loses essential information on the datetime object. So it's really best to use isoformat() instead of strtime() in all cases, so you are sure that if you end up comparing timestamps as string (i.e. in tests) you are sure it's going to work, including the timezone. Change-Id: I8b5119e64369ccac3423dccc04421f99912df733 --- oslo_utils/timeutils.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'oslo_utils/timeutils.py') diff --git a/oslo_utils/timeutils.py b/oslo_utils/timeutils.py index 9e15c12..7a01e8f 100644 --- a/oslo_utils/timeutils.py +++ b/oslo_utils/timeutils.py @@ -80,8 +80,24 @@ def parse_isotime(timestr): raise ValueError(six.text_type(e)) +@removals.remove( + message="use either datetime.datetime.isoformat() " + "or datetime.datetime.strftime() instead", + version="1.6", + removal_version="?", + ) def strtime(at=None, fmt=PERFECT_TIME_FORMAT): - """Returns formatted utcnow.""" + """Returns formatted utcnow. + + .. deprecated:: > 1.5.0 + Use :func:`utcnow()`, :func:`datetime.datetime.isoformat` + or :func:`datetime.strftime` instead. + + strtime() => utcnow().isoformat() + strtime(fmt=...) => utcnow().strftime(fmt) + strtime(at) => at.isoformat() + strtime(at, fmt) => at.strftime(fmt) + """ if not at: at = utcnow() return at.strftime(fmt) -- cgit v1.2.1