[issue40316] Add zero function to time, datetime, which acts as the use case of replace to limit resolution
Or Toledano added the comment: 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: https://stackoverflow.com/questions/13838394/can-i-easily-get-datetime-with-less-resolution-in-python which made me think that a zero function can be nice for that use case of datetime.replace -- ___ Python tracker <https://bugs.python.org/issue40316> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue40316] Add zero function to time, datetime, which acts as the use case of replace to limit resolution
Or Toledano added the comment: https://github.com/python/cpython/pull/19580 -- ___ Python tracker <https://bugs.python.org/issue40316> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue40316] Add zero function to time, datetime, which acts as the use case of replace to limit resolution
New submission from Or Toledano : I propose the zero(time_unit) function, which replaces all time units with greater equal resolution than time_unit by 0. E.g. >>> 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: -- components: Library (Lib) messages: 366696 nosy: Or Toledano, belopolsky, lemburg, p-ganssle priority: normal severity: normal status: open title: Add zero function to time, datetime, which acts as the use case of replace to limit resolution type: enhancement versions: Python 3.9 ___ Python tracker <https://bugs.python.org/issue40316> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue40316] Add zero function to time, datetime, which acts as the use case of replace to limit resolution
Change by Or Toledano : -- keywords: +patch pull_requests: +18918 stage: -> patch review pull_request: https://github.com/python/cpython/pull/19580 ___ Python tracker <https://bugs.python.org/issue40316> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com