diff options
author | Julien Danjou <julien@danjou.info> | 2015-01-20 12:04:58 +0100 |
---|---|---|
committer | Julien Danjou <julien@danjou.info> | 2015-06-01 12:48:06 +0200 |
commit | 4e01f29bafc75ef7c9ecc14cb7df25c6ba5c76cf (patch) | |
tree | a5de678c06b354608593ccef0e7a516dc445c8bd /oslo_utils/timeutils.py | |
parent | 74b3f97d089bd3c120e72bc27624875e50501bb5 (diff) | |
download | oslo-utils-4e01f29bafc75ef7c9ecc14cb7df25c6ba5c76cf.tar.gz |
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
Diffstat (limited to 'oslo_utils/timeutils.py')
-rw-r--r-- | oslo_utils/timeutils.py | 18 |
1 files changed, 17 insertions, 1 deletions
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) |