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.

classification
Title: Added datetime_diff to datetime.py.
Type: enhancement Stage: resolved
Components: Documentation, Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Decorater, Jim Fasarakis-Hilliard, belopolsky, docs@python, serhiy.storchaka
Priority: normal Keywords:

Created on 2017-03-21 06:25 by Decorater, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 749 closed Decorater, 2017-03-21 06:25
Messages (10)
msg289917 - (view) Author: Decorater (Decorater) * Date: 2017-03-21 06:25
The datetime_diff function compares two datetime objects and returns the time since the prior datetime objects (based on the current datetime object) in a what that is readable by humans.

This is useful when one might need to compare two datetime objects, keeping ones codebase as small as possible (to ensure fast Python code), and to reduce 'hacks' in their code to make the comparison more readable by humans

the github pull request comes with changes to datetime.rst as well

Note: This is currently targeting 3.7, however if you guys desire you guys could backport it into 3.5 and 3.6.
msg289918 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-03-21 06:35
In most cases you needed localized version. And I doubt that it makes much sense to output seconds seconds when the difference is larger than a year. Often you need to use other units for quantizations, e.g. "1 1/4 hours ago" as on this tracker.

This function doesn't look enough general for including in the stdlib.
msg289919 - (view) Author: Decorater (Decorater) * Date: 2017-03-21 06:41
I have people who would use it and there are use cases for it as well. Also it works perfectly fine the other one I added to it's docstring is an example datetime object of my very own discord account from when I created it.
msg289928 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-03-21 08:50
In that case you can publish your code as a receipt or as a module on PyPI. If it will be popular enough we can consider including it in the stdlib.

Currently your code is just broken.

>>> datetime.datetime_diff(datetime.datetime(2017, 1, 31), datetime.datetime(2017, 1, 31))
' ago.'
>>> datetime.datetime_diff(datetime.datetime(2016, 12, 31, 23, 59, 59), datetime.datetime(2017, 1, 1))
'1 years ago.'
>>> datetime.datetime_diff(datetime.datetime(2016, 1, 31), datetime.datetime(2017, 1, 31, 1))
'1 years1 hours ago.'
msg289947 - (view) Author: Decorater (Decorater) * Date: 2017-03-21 18:13
Oh, I just realized I forgot to add other if's to each block in case certain parts was 0 but others was not. I also realized I tried to do datetime.datetime.new instead of datetime.datetime.now on the tests.
msg289948 - (view) Author: Decorater (Decorater) * Date: 2017-03-21 18:36
Alright I revised it a bit locally too

>>> import datetime
>>> datetime.datetime_diff(datetime.datetime(2017, 1, 31), datetime.datetime(2017, 1, 31))
''
>>> datetime.datetime_diff(datetime.datetime(2016, 12, 31, 23, 59, 59), datetime.datetime(2017, 1, 1))
'1 year ago.'
>>> datetime.datetime_diff(datetime.datetime(2016, 1, 31), datetime.datetime(2017, 1, 31, 1))
'1 year, 1 hour ago.'
>>>
msg289949 - (view) Author: Decorater (Decorater) * Date: 2017-03-21 18:37
I plan to also have it to where if it is the last unit in the thing that it appends an and to the end as well.
msg289996 - (view) Author: Jim Fasarakis-Hilliard (Jim Fasarakis-Hilliard) * Date: 2017-03-22 16:18
Without stating an opinion on the change, I'd suggest first posting to python-ideas (unless you already did so and I missed it :-) to get an initial reaction from folks on your idea before coming to b.p.o.

If you have the backing of python-ideas you might have a good chance of having your change accepted.
msg290004 - (view) Author: Decorater (Decorater) * Date: 2017-03-22 17:53
Yeah, I could. I did just realize that there is a bug in it though that sometimes if it is like 58 seconds into a minute and you sleep for 15 that the code then thinks an entire minute elapsed when it has not. I need to think of a way to bypass that bug first. I found it after running tests many times locally (that actually run this time). Before it even gets accepted even with support from them I would have to fix that bug somehow.
msg290006 - (view) Author: Decorater (Decorater) * Date: 2017-03-22 18:04
an url preview of the bug itself https://travis-ci.org/AraHaan/datetime_diff/jobs/213944228
History
Date User Action Args
2022-04-11 14:58:44adminsetgithub: 74052
2017-03-22 18:04:40Decoratersetmessages: + msg290006
2017-03-22 17:53:29Decoratersetmessages: + msg290004
2017-03-22 16:18:20Jim Fasarakis-Hilliardsetnosy: + Jim Fasarakis-Hilliard
messages: + msg289996
2017-03-21 18:37:27Decoratersetmessages: + msg289949
2017-03-21 18:36:30Decoratersetmessages: + msg289948
2017-03-21 18:13:41Decoratersetmessages: + msg289947
2017-03-21 08:50:36serhiy.storchakasetstatus: open -> closed
resolution: rejected
messages: + msg289928

stage: patch review -> resolved
2017-03-21 06:41:15Decoratersetmessages: + msg289919
2017-03-21 06:35:04serhiy.storchakasetnosy: + serhiy.storchaka, belopolsky
messages: + msg289918

type: enhancement
stage: patch review
2017-03-21 06:25:36Decoratersetpull_requests: + pull_request663
2017-03-21 06:25:21Decoratercreate