timeago


Nametimeago JSON
Version 1.0.16 PyPI version JSON
download
home_pagehttps://github.com/hustcc/timeago
SummaryA very simple python library, used to format datetime with `*** time ago` statement. eg: "3 hours ago".
upload_time2022-08-18 21:54:38
maintainer
docs_urlNone
authorhustcc
requires_python
licenseMIT
keywords timeago seconds ago minutes ago hours ago just now
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            timeago
=======

A very simple python lib, used to format datetime with ``*** time ago``
statement. Javascript version here. `timeago.js`_.

|Build Status| |PyPi Status| |Python Versions|

Such as:

::

   just now
   12 seconds ago
   3 minutes ago
   2 hours ago
   24 days ago
   6 months ago
   2 years ago

   in 12 seconds
   in 3 minutes
   in 2 hours
   in 24 days
   in 6 months
   in 2 years

For other languages see below.

Install
-------

.. code:: sh

   pip install timeago

.. _usage--example:

Usage & Example
---------------

.. code:: py

   # -*- coding: utf-8 -*-
   import timeago, datetime

   now = datetime.datetime.now() + datetime.timedelta(seconds = 60 * 3.4)

   date = datetime.datetime.now()

   # locale
   print (timeago.format(date, now, 'zh_CN')) # will print `3分钟前`

   # input datetime
   print (timeago.format(date, now)) # will print 3 minutes ago

   # input timedelta
   print (timeago.format(datetime.timedelta(seconds = 60 * 3.4))) # will print 3 minutes ago

   # input date, auto add time(0, 0, 0)
   print (timeago.format(datetime.date(2016, 5, 27), now))

   # input datetime formatted string
   print (timeago.format('2016-05-27 12:12:03', '2016-05-27 12:12:12')) # will print just now

   # inverse two parameters
   print (timeago.format('2016-05-27 12:12:12', '2016-05-27 12:12:03')) # will print a while

.. _method--parameter:

Method & Parameter
------------------

only one API ``format``.

Three parameters of method ``format``:

-  ``date``: the parameter which will be formatted, must be instance
   of ``datetime`` / ``timedelta`` or datetime formatted string.
-  ``now``: reference time, must be instance of ``datetime`` or
   datetime formatted string.
-  ``locale``: the locale code, default ``en``.

Locale
------

At the time we're speaking, `following locale`_ are available:

-  ``ar``
-  ``bg``
-  ``ca``
-  ``da``
-  ``de``
-  ``el``
-  ``en``
-  ``en_short``
-  ``es``
-  ``eu``
-  ``fa_IR``
-  ``fi``
-  ``fr``
-  ``gl``
-  ``guj_IN``
-  ``he``
-  ``hu``
-  ``in_BG``
-  ``in_HI``
-  ``in_ID``
-  ``is``
-  ``it``
-  ``ja``
-  ``ko``
-  ``lt``
-  ``ml``
-  ``my``
-  ``nb_NO``
-  ``nl``
-  ``nn_NO``
-  ``pl``
-  ``pt_PT``
-  ``pt_BR``
-  ``ro``
-  ``ru``
-  ``sk``
-  ``sv_SE``
-  ``ta``
-  ``th``
-  ``tr``
-  ``uk``
-  ``vi``
-  ``zh_CN``
-  ``zh_TW``

Localization
------------

1. Fork the project
2. Create a locale python script called ``[name_of_your_locale].py``
   following the existing other locales.
3. Add the name of your locale in the Readme to keep it updated
   (**alphabetically**).
4. Add test case following the `english model`_
5. Create the Pull Request.

Notes
~~~~~

For complicated plurals, you can take example on the PL (Polish) locale
`here`_

.. _timeago.js: https://github.com/hustcc/timeago.js
.. _following locale: https://github.com/hustcc/timeago/tree/master/src/timeago/locales
.. _english model: https://github.com/hustcc/timeago/tree/master/test/testcase.py#L50
.. _here: https://github.com/hustcc/timeago/tree/master/src/timeago/locales/pl.py

.. |Build Status| image:: https://travis-ci.org/hustcc/timeago.svg?branch=master
   :target: https://travis-ci.org/hustcc/timeago
.. |PyPi Status| image:: https://img.shields.io/pypi/v/timeago.svg
   :target: https://pypi.python.org/pypi/timeago
.. |Python Versions| image:: https://img.shields.io/pypi/pyversions/timeago.svg
   :target: https://pypi.python.org/pypi/timeago



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hustcc/timeago",
    "name": "timeago",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "timeago,seconds ago,minutes ago,hours ago,just now",
    "author": "hustcc",
    "author_email": "i@hust.cc",
    "download_url": "",
    "platform": null,
    "description": "timeago\n=======\n\nA very simple python lib, used to format datetime with ``*** time ago``\nstatement. Javascript version here. `timeago.js`_.\n\n|Build Status| |PyPi Status| |Python Versions|\n\nSuch as:\n\n::\n\n   just now\n   12 seconds ago\n   3 minutes ago\n   2 hours ago\n   24 days ago\n   6 months ago\n   2 years ago\n\n   in 12 seconds\n   in 3 minutes\n   in 2 hours\n   in 24 days\n   in 6 months\n   in 2 years\n\nFor other languages see below.\n\nInstall\n-------\n\n.. code:: sh\n\n   pip install timeago\n\n.. _usage--example:\n\nUsage & Example\n---------------\n\n.. code:: py\n\n   # -*- coding: utf-8 -*-\n   import timeago, datetime\n\n   now = datetime.datetime.now() + datetime.timedelta(seconds = 60 * 3.4)\n\n   date = datetime.datetime.now()\n\n   # locale\n   print (timeago.format(date, now, 'zh_CN')) # will print `3\u5206\u949f\u524d`\n\n   # input datetime\n   print (timeago.format(date, now)) # will print 3 minutes ago\n\n   # input timedelta\n   print (timeago.format(datetime.timedelta(seconds = 60 * 3.4))) # will print 3 minutes ago\n\n   # input date, auto add time(0, 0, 0)\n   print (timeago.format(datetime.date(2016, 5, 27), now))\n\n   # input datetime formatted string\n   print (timeago.format('2016-05-27 12:12:03', '2016-05-27 12:12:12')) # will print just now\n\n   # inverse two parameters\n   print (timeago.format('2016-05-27 12:12:12', '2016-05-27 12:12:03')) # will print a while\n\n.. _method--parameter:\n\nMethod & Parameter\n------------------\n\nonly one API ``format``.\n\nThree parameters of method ``format``:\n\n-  ``date``: the parameter which will be formatted, must be instance\n   of ``datetime`` / ``timedelta`` or datetime formatted string.\n-  ``now``: reference time, must be instance of ``datetime`` or\n   datetime formatted string.\n-  ``locale``: the locale code, default ``en``.\n\nLocale\n------\n\nAt the time we're speaking, `following locale`_ are available:\n\n-  ``ar``\n-  ``bg``\n-  ``ca``\n-  ``da``\n-  ``de``\n-  ``el``\n-  ``en``\n-  ``en_short``\n-  ``es``\n-  ``eu``\n-  ``fa_IR``\n-  ``fi``\n-  ``fr``\n-  ``gl``\n-  ``guj_IN``\n-  ``he``\n-  ``hu``\n-  ``in_BG``\n-  ``in_HI``\n-  ``in_ID``\n-  ``is``\n-  ``it``\n-  ``ja``\n-  ``ko``\n-  ``lt``\n-  ``ml``\n-  ``my``\n-  ``nb_NO``\n-  ``nl``\n-  ``nn_NO``\n-  ``pl``\n-  ``pt_PT``\n-  ``pt_BR``\n-  ``ro``\n-  ``ru``\n-  ``sk``\n-  ``sv_SE``\n-  ``ta``\n-  ``th``\n-  ``tr``\n-  ``uk``\n-  ``vi``\n-  ``zh_CN``\n-  ``zh_TW``\n\nLocalization\n------------\n\n1. Fork the project\n2. Create a locale python script called ``[name_of_your_locale].py``\n   following the existing other locales.\n3. Add the name of your locale in the Readme to keep it updated\n   (**alphabetically**).\n4. Add test case following the `english model`_\n5. Create the Pull Request.\n\nNotes\n~~~~~\n\nFor complicated plurals, you can take example on the PL (Polish) locale\n`here`_\n\n.. _timeago.js: https://github.com/hustcc/timeago.js\n.. _following locale: https://github.com/hustcc/timeago/tree/master/src/timeago/locales\n.. _english model: https://github.com/hustcc/timeago/tree/master/test/testcase.py#L50\n.. _here: https://github.com/hustcc/timeago/tree/master/src/timeago/locales/pl.py\n\n.. |Build Status| image:: https://travis-ci.org/hustcc/timeago.svg?branch=master\n   :target: https://travis-ci.org/hustcc/timeago\n.. |PyPi Status| image:: https://img.shields.io/pypi/v/timeago.svg\n   :target: https://pypi.python.org/pypi/timeago\n.. |Python Versions| image:: https://img.shields.io/pypi/pyversions/timeago.svg\n   :target: https://pypi.python.org/pypi/timeago\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A very simple python library, used to format datetime with `*** time ago` statement. eg: \"3 hours ago\".",
    "version": "1.0.16",
    "split_keywords": [
        "timeago",
        "seconds ago",
        "minutes ago",
        "hours ago",
        "just now"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "8b9bab63c31e2ecb10099f3c40db8cc8",
                "sha256": "9b8cb2e3102b329f35a04aa4531982d867b093b19481cfbb1dac7845fa2f79b0"
            },
            "downloads": -1,
            "filename": "timeago-1.0.16-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8b9bab63c31e2ecb10099f3c40db8cc8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 29693,
            "upload_time": "2022-08-18T21:54:38",
            "upload_time_iso_8601": "2022-08-18T21:54:38.399256Z",
            "url": "https://files.pythonhosted.org/packages/5f/88/8dac5496354650972434966ba570a4a824fafed43471cf190faea4b085fc/timeago-1.0.16-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-08-18 21:54:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "hustcc",
    "github_project": "timeago",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "timeago"
}
        
Elapsed time: 0.02078s