Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added datetime_diff to datetime.py. #74052

Closed
AraHaan mannequin opened this issue Mar 21, 2017 · 10 comments
Closed

Added datetime_diff to datetime.py. #74052

AraHaan mannequin opened this issue Mar 21, 2017 · 10 comments
Labels
3.7 (EOL) end of life docs Documentation in the Doc dir stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@AraHaan
Copy link
Mannequin

AraHaan mannequin commented Mar 21, 2017

BPO 29866
Nosy @abalkin, @serhiy-storchaka, @AraHaan, @DimitrisJim
PRs
  • bpo-29866: Added datetime_diff to datetime.py. #749
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2017-03-21.08:50:36.813>
    created_at = <Date 2017-03-21.06:25:21.779>
    labels = ['3.7', 'type-feature', 'library', 'docs']
    title = 'Added datetime_diff to datetime.py.'
    updated_at = <Date 2017-03-22.18:04:40.560>
    user = 'https://github.com/AraHaan'

    bugs.python.org fields:

    activity = <Date 2017-03-22.18:04:40.560>
    actor = 'Decorater'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2017-03-21.08:50:36.813>
    closer = 'serhiy.storchaka'
    components = ['Documentation', 'Library (Lib)']
    creation = <Date 2017-03-21.06:25:21.779>
    creator = 'Decorater'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 29866
    keywords = []
    message_count = 10.0
    messages = ['289917', '289918', '289919', '289928', '289947', '289948', '289949', '289996', '290004', '290006']
    nosy_count = 5.0
    nosy_names = ['belopolsky', 'docs@python', 'serhiy.storchaka', 'Decorater', 'Jim Fasarakis-Hilliard']
    pr_nums = ['749']
    priority = 'normal'
    resolution = 'rejected'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue29866'
    versions = ['Python 3.7']

    @AraHaan
    Copy link
    Mannequin Author

    AraHaan mannequin commented Mar 21, 2017

    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.

    @AraHaan AraHaan mannequin added the 3.7 (EOL) end of life label Mar 21, 2017
    @AraHaan AraHaan mannequin assigned docspython Mar 21, 2017
    @AraHaan AraHaan mannequin added docs Documentation in the Doc dir stdlib Python modules in the Lib dir labels Mar 21, 2017
    @serhiy-storchaka
    Copy link
    Member

    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.

    @serhiy-storchaka serhiy-storchaka added the type-feature A feature request or enhancement label Mar 21, 2017
    @AraHaan
    Copy link
    Mannequin Author

    AraHaan mannequin commented Mar 21, 2017

    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.

    @serhiy-storchaka
    Copy link
    Member

    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.'

    @AraHaan
    Copy link
    Mannequin Author

    AraHaan mannequin commented Mar 21, 2017

    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.

    @AraHaan
    Copy link
    Mannequin Author

    AraHaan mannequin commented Mar 21, 2017

    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.'
    >>>

    @AraHaan
    Copy link
    Mannequin Author

    AraHaan mannequin commented Mar 21, 2017

    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.

    @DimitrisJim
    Copy link
    Mannequin

    DimitrisJim mannequin commented Mar 22, 2017

    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.

    @AraHaan
    Copy link
    Mannequin Author

    AraHaan mannequin commented Mar 22, 2017

    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.

    @AraHaan
    Copy link
    Mannequin Author

    AraHaan mannequin commented Mar 22, 2017

    an url preview of the bug itself https://travis-ci.org/AraHaan/datetime_diff/jobs/213944228

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life docs Documentation in the Doc dir stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant