pytimeparse


Namepytimeparse JSON
Version 1.1.8 PyPI version JSON
download
home_pagehttps://github.com/wroberts/pytimeparse
SummaryTime expression parser
upload_time2018-05-18 17:40:42
maintainer
docs_urlNone
authorWill Roberts
requires_python
licenseLicense :: OSI Approved :: MIT License
keywords time parsing parser
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            =====================================
 pytimeparse: time expression parser
=====================================

.. image:: https://travis-ci.org/wroberts/pytimeparse.svg?branch=master
    :target: https://travis-ci.org/wroberts/pytimeparse
    :alt: Travis CI build status

.. image:: https://coveralls.io/repos/wroberts/pytimeparse/badge.svg
    :target: https://coveralls.io/r/wroberts/pytimeparse
    :alt: Test code coverage

.. image:: https://img.shields.io/pypi/v/pytimeparse.svg
    :target: https://pypi.python.org/pypi/pytimeparse/
    :alt: Latest Version

Copyright (c) 2014 Will Roberts <wildwilhelm@gmail.com>

Licensed under the MIT License (see source file ``timeparse.py`` for
details).

A small Python library to parse various kinds of time expressions,
inspired by
`this StackOverflow question <http://stackoverflow.com/questions/4628122/how-to-construct-a-timedelta-object-from-a-simple-string>`_.

The single function ``pytimeparse.timeparse.timeparse`` defined in the
library (also available as ``pytimeparse.parse``) parses time
expressions like the following:

- ``32m``
- ``2h32m``
- ``3d2h32m``
- ``1w3d2h32m``
- ``1w 3d 2h 32m``
- ``1 w 3 d 2 h 32 m``
- ``4:13``
- ``4:13:02``
- ``4:13:02.266``
- ``2:04:13:02.266``
- ``2 days,  4:13:02`` (``uptime`` format)
- ``2 days,  4:13:02.266``
- ``5hr34m56s``
- ``5 hours, 34 minutes, 56 seconds``
- ``5 hrs, 34 mins, 56 secs``
- ``2 days, 5 hours, 34 minutes, 56 seconds``
- ``1.2 m``
- ``1.2 min``
- ``1.2 mins``
- ``1.2 minute``
- ``1.2 minutes``
- ``172 hours``
- ``172 hr``
- ``172 h``
- ``172 hrs``
- ``172 hour``
- ``1.24 days``
- ``5 d``
- ``5 day``
- ``5 days``
- ``5.6 wk``
- ``5.6 week``
- ``5.6 weeks``

It returns the time as a number of seconds (an integer value if
possible, otherwise a floating-point number)::

    >>> from pytimeparse import parse
    >>> parse('1.2 minutes')
    72

A number of seconds can be converted back into a string using the
``datetime`` module in the standard library, as noted in
`this other StackOverflow question <http://stackoverflow.com/questions/538666/python-format-timedelta-to-string>`_::

    >>> from pytimeparse import parse
    >>> import datetime
    >>> parse('1 day, 14:20:16')
    138016
    >>> str(datetime.timedelta(seconds=138016))
    '1 day, 14:20:16'

Future work
-----------

1. Give the user more flexibility over which characters to use as
   separators between fields in a time expression (e.g., ``+`` might
   be useful).
2. Internationalisation?
3. Wow, https://github.com/bear/parsedatetime .



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/wroberts/pytimeparse",
    "name": "pytimeparse",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "time parsing parser",
    "author": "Will Roberts",
    "author_email": "wildwilhelm@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/37/5d/231f5f33c81e09682708fb323f9e4041408d8223e2f0fb9742843328778f/pytimeparse-1.1.8.tar.gz",
    "platform": "",
    "description": "=====================================\n pytimeparse: time expression parser\n=====================================\n\n.. image:: https://travis-ci.org/wroberts/pytimeparse.svg?branch=master\n    :target: https://travis-ci.org/wroberts/pytimeparse\n    :alt: Travis CI build status\n\n.. image:: https://coveralls.io/repos/wroberts/pytimeparse/badge.svg\n    :target: https://coveralls.io/r/wroberts/pytimeparse\n    :alt: Test code coverage\n\n.. image:: https://img.shields.io/pypi/v/pytimeparse.svg\n    :target: https://pypi.python.org/pypi/pytimeparse/\n    :alt: Latest Version\n\nCopyright (c) 2014 Will Roberts <wildwilhelm@gmail.com>\n\nLicensed under the MIT License (see source file ``timeparse.py`` for\ndetails).\n\nA small Python library to parse various kinds of time expressions,\ninspired by\n`this StackOverflow question <http://stackoverflow.com/questions/4628122/how-to-construct-a-timedelta-object-from-a-simple-string>`_.\n\nThe single function ``pytimeparse.timeparse.timeparse`` defined in the\nlibrary (also available as ``pytimeparse.parse``) parses time\nexpressions like the following:\n\n- ``32m``\n- ``2h32m``\n- ``3d2h32m``\n- ``1w3d2h32m``\n- ``1w 3d 2h 32m``\n- ``1 w 3 d 2 h 32 m``\n- ``4:13``\n- ``4:13:02``\n- ``4:13:02.266``\n- ``2:04:13:02.266``\n- ``2 days,  4:13:02`` (``uptime`` format)\n- ``2 days,  4:13:02.266``\n- ``5hr34m56s``\n- ``5 hours, 34 minutes, 56 seconds``\n- ``5 hrs, 34 mins, 56 secs``\n- ``2 days, 5 hours, 34 minutes, 56 seconds``\n- ``1.2 m``\n- ``1.2 min``\n- ``1.2 mins``\n- ``1.2 minute``\n- ``1.2 minutes``\n- ``172 hours``\n- ``172 hr``\n- ``172 h``\n- ``172 hrs``\n- ``172 hour``\n- ``1.24 days``\n- ``5 d``\n- ``5 day``\n- ``5 days``\n- ``5.6 wk``\n- ``5.6 week``\n- ``5.6 weeks``\n\nIt returns the time as a number of seconds (an integer value if\npossible, otherwise a floating-point number)::\n\n    >>> from pytimeparse import parse\n    >>> parse('1.2 minutes')\n    72\n\nA number of seconds can be converted back into a string using the\n``datetime`` module in the standard library, as noted in\n`this other StackOverflow question <http://stackoverflow.com/questions/538666/python-format-timedelta-to-string>`_::\n\n    >>> from pytimeparse import parse\n    >>> import datetime\n    >>> parse('1 day, 14:20:16')\n    138016\n    >>> str(datetime.timedelta(seconds=138016))\n    '1 day, 14:20:16'\n\nFuture work\n-----------\n\n1. Give the user more flexibility over which characters to use as\n   separators between fields in a time expression (e.g., ``+`` might\n   be useful).\n2. Internationalisation?\n3. Wow, https://github.com/bear/parsedatetime .\n\n\n",
    "bugtrack_url": null,
    "license": "License :: OSI Approved :: MIT License",
    "summary": "Time expression parser",
    "version": "1.1.8",
    "split_keywords": [
        "time",
        "parsing",
        "parser"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "f8c5c884bde663f095b6ca30f3bd54a4",
                "sha256": "04b7be6cc8bd9f5647a6325444926c3ac34ee6bc7e69da4367ba282f076036bd"
            },
            "downloads": -1,
            "filename": "pytimeparse-1.1.8-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f8c5c884bde663f095b6ca30f3bd54a4",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 9969,
            "upload_time": "2018-05-18T17:40:41",
            "upload_time_iso_8601": "2018-05-18T17:40:41.280151Z",
            "url": "https://files.pythonhosted.org/packages/1b/b4/afd75551a3b910abd1d922dbd45e49e5deeb4d47dc50209ce489ba9844dd/pytimeparse-1.1.8-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "341b267e27e843eccaa839b91b16165b",
                "sha256": "e86136477be924d7e670646a98561957e8ca7308d44841e21f5ddea757556a0a"
            },
            "downloads": -1,
            "filename": "pytimeparse-1.1.8.tar.gz",
            "has_sig": false,
            "md5_digest": "341b267e27e843eccaa839b91b16165b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 9403,
            "upload_time": "2018-05-18T17:40:42",
            "upload_time_iso_8601": "2018-05-18T17:40:42.760633Z",
            "url": "https://files.pythonhosted.org/packages/37/5d/231f5f33c81e09682708fb323f9e4041408d8223e2f0fb9742843328778f/pytimeparse-1.1.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2018-05-18 17:40:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "wroberts",
    "github_project": "pytimeparse",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pytimeparse"
}
        
Elapsed time: 0.01866s