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) *  |
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) *  |
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 |
|
|