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
This commit is contained in:
Julien Danjou 2015-01-20 12:04:58 +01:00
parent 74b3f97d08
commit 4e01f29baf

View File

@ -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)