This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Add zero function to time, datetime, which acts as the use case of replace to limit resolution
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.9
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: Or Toledano, SilentGhost, belopolsky, lemburg, p-ganssle, rhettinger, terry.reedy
Priority: normal Keywords: patch

Created on 2020-04-18 09:37 by Or Toledano, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19580 closed Or Toledano, 2020-04-18 09:37
Messages (6)
msg366696 - (view) Author: Or Toledano (Or Toledano) * Date: 2020-04-18 09:37
I propose the zero(time_unit) function, which replaces all time units with greater equal resolution than time_unit by 0.
>>> datetime.datetime(2020, 4, 18, 12, 27, 30, 500).zero("second")
datetime.datetime(2020, 4, 18, 12, 27)
I purpose it for the datetime, time classes.
I also added unit tests for the function in those classes.
GitHub PR:
msg366697 - (view) Author: Or Toledano (Or Toledano) * Date: 2020-04-18 09:38
msg366699 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2020-04-18 11:18
What is the use-case for this new method?
msg366700 - (view) Author: Or Toledano (Or Toledano) * Date: 2020-04-18 11:30
The use-case for this method is to "limit" the resolution of a time object.
I encountered the need for it when I needed to reduce the resolution of some timestamps, to compare them with timestamps of lesser resolution.
I found the following SOF post:
which made me think that a zero function can be nice for that use case of datetime.replace
msg367729 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-04-30 01:48
I recommend posting this to python-ideas for discussion.
msg368103 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-05-05 04:17
FWIW, I like the answer in the StackOverflow link better than this proposal.

At any rate, I think Terry's suggestion is a good one.  If you would like to move forward with this, please take it to python-ideas.

That said, if another core-dev wants to champion this, feel free to re-open.
Date User Action Args
2022-04-11 14:59:29adminsetgithub: 84496
2020-05-05 04:17:00rhettingersetstatus: open -> closed

nosy: + rhettinger
messages: + msg368103

resolution: rejected
stage: patch review -> resolved
2020-04-30 01:48:09terry.reedysetnosy: + terry.reedy
messages: + msg367729
2020-04-18 11:30:07Or Toledanosetmessages: + msg366700
2020-04-18 11:18:34SilentGhostsetnosy: + SilentGhost
messages: + msg366699
2020-04-18 09:38:52Or Toledanosetmessages: + msg366697
2020-04-18 09:37:50Or Toledanosetkeywords: + patch
stage: patch review
pull_requests: + pull_request18918
2020-04-18 09:37:15Or Toledanocreate