ago


Nameago JSON
Version 0.0.95 PyPI version JSON
download
home_pagehttps://git.unturf.com/python/ago
Summaryago: Human readable timedeltas
upload_time2022-07-11 21:04:10
maintainer
docs_urlNone
authorRussell Ballestrini
requires_python
licensePublic Domain
keywords ago human readable time deltas timedelta datetime timestamp
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            What are human readable timedeltas? 
===============================================

ago.py makes customizable human readable timedeltas, for example:

Testing past tense::

 Russell commented 1 year, 127 days, 16 hours ago
 You replied 1 year, 127 days ago

Testing future tense::

 Program will shutdown in 2 days, 3 hours, 27 minutes
 Job will run 2 days, 3 hours from now


How to install
===================

There are a number of ways to install this package.

You could run this ad hoc command::

 pip install ago

or specify *ago* under the *setup_requires* list within your
*setuptools*-compatible project's *setup.py* file.


How to use
==================

The ago module comes with three functions: 

#. human
#. delta2dict
#. get_delta_from_subject

You really only need to worry about *human*.

Here are all the available arguments and defaults::

 human(subject, precision=2, past_tense='{} ago', future_tense='in {}', abbreviate=False):

subject
 a datetime, timedelta, or timestamp (integer/float) object to become human readable

precision (default 2):
 the desired amount of unit precision

past_tense (default '{} ago'):
 the format string used for a past timedelta

future_tense (default 'in {}'):
 the format string used for a future timedelta

abbreviate (default False):
 boolean to abbreviate units

Here is an example on how to use *human*::

 from ago import human
 from ago import delta2dict
 
 from datetime import datetime
 from datetime import timedelta

 # pretend this was stored in database
 db_date = datetime(year=2010, month=5, day=4, hour=6, minute=54, second=33, microsecond=4000)

 # to find out how long ago, use the human function
 print 'Created ' + human( db_date )
 
 # optionally pass a precision
 print 'Created ' + human( db_date, 3 )
 print 'Created ' + human( db_date, 6 )

We also support future dates and times::

 PRESENT = datetime.now()
 PAST = PRESENT - timedelta( 492, 58711, 45 ) # days, secs, ms
 FUTURE = PRESENT + timedelta( 2, 12447, 963 ) # days, secs, ms

 print human( FUTURE )

Example past_tense and future_tense keyword arguments::

 output1 = human( PAST,
   past_tense = 'titanic sunk {0} ago',
   future_tense = 'titanic will sink in {0} from now'
 )

 output2 = human( FUTURE,
   past_tense = 'titanic sunk {0} ago',
   future_tense = 'titanic will sink in {0} from now'
 )

 print output1
 # titanic sunk 1 year, 127 days ago
 print output2
 # titanic will sink in 2 days, 3 hours from now


Need more examples?
==========================

You should look at test_ago.py


How do I thank you?
==========================

You should follow me on twitter http://twitter.com/russellbal


License
=========================

* Public Domain


Public Revision Control
==============================

* https://git.unturf.com/python/ago



            

Raw data

            {
    "_id": null,
    "home_page": "https://git.unturf.com/python/ago",
    "name": "ago",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "ago human readable time deltas timedelta datetime timestamp",
    "author": "Russell Ballestrini",
    "author_email": "russell.ballestrini@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b2/32/cba29ff61c24dac4b2f24f95b319f770a63d5a05f423102dcbf18950e7e8/ago-0.0.95.tar.gz",
    "platform": "All",
    "description": "What are human readable timedeltas? \n===============================================\n\nago.py makes customizable human readable timedeltas, for example:\n\nTesting past tense::\n\n Russell commented 1 year, 127 days, 16 hours ago\n You replied 1 year, 127 days ago\n\nTesting future tense::\n\n Program will shutdown in 2 days, 3 hours, 27 minutes\n Job will run 2 days, 3 hours from now\n\n\nHow to install\n===================\n\nThere are a number of ways to install this package.\n\nYou could run this ad hoc command::\n\n pip install ago\n\nor specify *ago* under the *setup_requires* list within your\n*setuptools*-compatible project's *setup.py* file.\n\n\nHow to use\n==================\n\nThe ago module comes with three functions: \n\n#. human\n#. delta2dict\n#. get_delta_from_subject\n\nYou really only need to worry about *human*.\n\nHere are all the available arguments and defaults::\n\n human(subject, precision=2, past_tense='{} ago', future_tense='in {}', abbreviate=False):\n\nsubject\n a datetime, timedelta, or timestamp (integer/float) object to become human readable\n\nprecision (default 2):\n the desired amount of unit precision\n\npast_tense (default '{} ago'):\n the format string used for a past timedelta\n\nfuture_tense (default 'in {}'):\n the format string used for a future timedelta\n\nabbreviate (default False):\n boolean to abbreviate units\n\nHere is an example on how to use *human*::\n\n from ago import human\n from ago import delta2dict\n \n from datetime import datetime\n from datetime import timedelta\n\n # pretend this was stored in database\n db_date = datetime(year=2010, month=5, day=4, hour=6, minute=54, second=33, microsecond=4000)\n\n # to find out how long ago, use the human function\n print 'Created ' + human( db_date )\n \n # optionally pass a precision\n print 'Created ' + human( db_date, 3 )\n print 'Created ' + human( db_date, 6 )\n\nWe also support future dates and times::\n\n PRESENT = datetime.now()\n PAST = PRESENT - timedelta( 492, 58711, 45 ) # days, secs, ms\n FUTURE = PRESENT + timedelta( 2, 12447, 963 ) # days, secs, ms\n\n print human( FUTURE )\n\nExample past_tense and future_tense keyword arguments::\n\n output1 = human( PAST,\n   past_tense = 'titanic sunk {0} ago',\n   future_tense = 'titanic will sink in {0} from now'\n )\n\n output2 = human( FUTURE,\n   past_tense = 'titanic sunk {0} ago',\n   future_tense = 'titanic will sink in {0} from now'\n )\n\n print output1\n # titanic sunk 1 year, 127 days ago\n print output2\n # titanic will sink in 2 days, 3 hours from now\n\n\nNeed more examples?\n==========================\n\nYou should look at test_ago.py\n\n\nHow do I thank you?\n==========================\n\nYou should follow me on twitter http://twitter.com/russellbal\n\n\nLicense\n=========================\n\n* Public Domain\n\n\nPublic Revision Control\n==============================\n\n* https://git.unturf.com/python/ago\n\n\n",
    "bugtrack_url": null,
    "license": "Public Domain",
    "summary": "ago: Human readable timedeltas",
    "version": "0.0.95",
    "project_urls": {
        "Homepage": "https://git.unturf.com/python/ago"
    },
    "split_keywords": [
        "ago",
        "human",
        "readable",
        "time",
        "deltas",
        "timedelta",
        "datetime",
        "timestamp"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "26c85d1a57f41b99e2e33cdf7a75e924b2f67748f88d539720ad7f765f34463c",
                "md5": "ba953f14c1939f7a7b0f86eb37eae073",
                "sha256": "f95171f81060b712f2ca05111fc4b38ef958a5cd1ad3c06b633f9b82de92eeaf"
            },
            "downloads": -1,
            "filename": "ago-0.0.95-py3.10.egg",
            "has_sig": false,
            "md5_digest": "ba953f14c1939f7a7b0f86eb37eae073",
            "packagetype": "bdist_egg",
            "python_version": "0.0.95",
            "requires_python": null,
            "size": 13564,
            "upload_time": "2022-07-11T21:04:08",
            "upload_time_iso_8601": "2022-07-11T21:04:08.035368Z",
            "url": "https://files.pythonhosted.org/packages/26/c8/5d1a57f41b99e2e33cdf7a75e924b2f67748f88d539720ad7f765f34463c/ago-0.0.95-py3.10.egg",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b232cba29ff61c24dac4b2f24f95b319f770a63d5a05f423102dcbf18950e7e8",
                "md5": "4976b8f6a70b001f839615d8c2dd6304",
                "sha256": "d2010f5eac3df544ec48ec116102e068591a345b1a580f32973db8a505fca744"
            },
            "downloads": -1,
            "filename": "ago-0.0.95.tar.gz",
            "has_sig": false,
            "md5_digest": "4976b8f6a70b001f839615d8c2dd6304",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4579,
            "upload_time": "2022-07-11T21:04:10",
            "upload_time_iso_8601": "2022-07-11T21:04:10.028712Z",
            "url": "https://files.pythonhosted.org/packages/b2/32/cba29ff61c24dac4b2f24f95b319f770a63d5a05f423102dcbf18950e7e8/ago-0.0.95.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-07-11 21:04:10",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "ago"
}
        
Elapsed time: 0.26299s