Issue 1296581: datetime.replace could take a dict (original) (raw)
Python 2.4.1.
datetime.replace uses its kwargs to specify the fields, which I found a bit surprising. It could also take an equivalent dict. (Failing that, it could have a fuller docstring.)
What I was actually trying to do was round to the nearest half hour. floor and ceil methods taking a timedelta would be nice too.
Logged In: YES user_id=80475
Any function accepting keyword arguments can already be called with an equivalent dict using the ** notation (similar to tuple unpacking):
from datetime import date d = dict(day=26, year=2004) date(2001, 1, 2).replace(**d) datetime.date(2004, 1, 26)