[issue32522] Add precision argument to datetime.now

Paul Ganssle report at bugs.python.org
Tue Jan 9 11:33:19 EST 2018


Paul Ganssle <p.ganssle at gmail.com> added the comment:

@Barry I don't think it's a good idea to duplicate the `replace` functionality in `datetime` like that. I think the main problem isn't the `.replace`, it's the fact that you have to specify exactly which components you want to set to zero - to get "the beginning of this month" or "today at midnight" or "the beginning of the current hour" or "the beginning of the current minute", you have to manually replace a whole list of these components.

It doesn't help that `datetime.today()` leaks implementation details from `date.today()`, thus making it a slower, worse version of `datetime.now()`, since the overwhelmingly most common use cases for datetime rounding are probably "get today at midnight" and "get the current time with second precision". Still, I think a more general fix would be better now and in the future.

Even if we had "get today at midnight" and a `microseconds=0` argument to `datetime.now`, without a more general version of this, if (or possibly *when*) nanosecond precision is added to `datetime`, you'd now start having to add `microseconds=0, nanoseconds=0` or something to `datetime` (depending on the implementation of nanoseconds).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32522>
_______________________________________


More information about the Python-bugs-list mailing list