isodate


Nameisodate JSON
Version 0.7.2 PyPI version JSON
download
home_pageNone
SummaryAn ISO 8601 date/time/duration parser and formatter
upload_time2024-10-08 23:04:11
maintainerNone
docs_urlNone
authorGerhard Weis
requires_python>=3.7
licenseCopyright (c) 2021, Hugo van Kemenade and contributors Copyright (c) 2009-2018, Gerhard Weis and contributors Copyright (c) 2009, Gerhard Weis All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the <organization> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
ISO 8601 date/time parser
=========================

.. image:: https://travis-ci.org/gweis/isodate.svg?branch=master
    :target: https://travis-ci.org/gweis/isodate
    :alt: Travis-CI
.. image:: https://coveralls.io/repos/gweis/isodate/badge.svg?branch=master
    :target: https://coveralls.io/r/gweis/isodate?branch=master
    :alt: Coveralls
.. image:: https://img.shields.io/pypi/v/isodate.svg
    :target: https://pypi.python.org/pypi/isodate/
    :alt: Latest Version
.. image:: https://img.shields.io/pypi/l/isodate.svg
    :target: https://pypi.python.org/pypi/isodate/
    :alt: License


This module implements ISO 8601 date, time and duration parsing.
The implementation follows ISO8601:2004 standard, and implements only
date/time representations mentioned in the standard. If something is not
mentioned there, then it is treated as non existent, and not as an allowed
option.

For instance, ISO8601:2004 never mentions 2 digit years. So, it is not
intended by this module to support 2 digit years. (while it may still
be valid as ISO date, because it is not explicitly forbidden.)
Another example is, when no time zone information is given for a time,
then it should be interpreted as local time, and not UTC.

As this module maps ISO 8601 dates/times to standard Python data types, like
*date*, *time*, *datetime* and *timedelta*, it is not possible to convert
all possible ISO 8601 dates/times. For instance, dates before 0001-01-01 are
not allowed by the Python *date* and *datetime* classes. Additionally
fractional seconds are limited to microseconds. That means if the parser finds
for instance nanoseconds it will round it down to microseconds.

Documentation
-------------

The following parsing methods are available.
   * parse_time:
        parses an ISO 8601 time string into a *time* object
   * parse_date:
        parses an ISO 8601 date string into a *date* object
   * parse_datetime:
        parses an ISO 8601 date-time string into a *datetime* object
   * parse_duration:
        parses an ISO 8601 duration string into a *timedelta* or *Duration*
        object.
   * parse_tzinfo:
        parses the time zone info part of an ISO 8601 string into a
        *tzinfo* object.

As ISO 8601 allows to define durations in years and months, and *timedelta*
does not handle years and months, this module provides a *Duration* class,
which can be used almost like a *timedelta* object (with some limitations).
However, a *Duration* object can be converted into a *timedelta* object.

There are also ISO formatting methods for all supported data types. Each
*xxx_isoformat* method accepts a format parameter. The default format is
always the ISO 8601 expanded format. This is the same format used by
*datetime.isoformat*:

    * time_isoformat:
        Intended to create ISO time strings with default format
        *hh:mm:ssZ*.
    * date_isoformat:
        Intended to create ISO date strings with default format
        *yyyy-mm-dd*.
    * datetime_isoformat:
        Intended to create ISO date-time strings with default format
        *yyyy-mm-ddThh:mm:ssZ*.
    * duration_isoformat:
        Intended to create ISO duration strings with default format
        *PnnYnnMnnDTnnHnnMnnS*.
    * tz_isoformat:
        Intended to create ISO time zone strings with default format
        *hh:mm*.
    * strftime:
        A re-implementation mostly compatible with Python's *strftime*, but
        supports only those format strings, which can also be used for dates
        prior 1900. This method also understands how to format *datetime* and
        *Duration* instances.

Installation
------------

This module can easily be installed with Python standard installation methods.

Use *pip install isodate*.

Limitations
-----------

   * The parser accepts several date/time representation which should be invalid
     according to ISO 8601 standard.

     1. for date and time together, this parser accepts a mixture of basic and extended format.
        e.g. the date could be in basic format, while the time is accepted in extended format.
        It also allows short dates and times in date-time strings.
     2. For incomplete dates, the first day is chosen. e.g. 19th century results in a date of
        1901-01-01.
     3. negative *Duration* and *timedelta* value are not fully supported yet.

Further information
-------------------

The doc strings and unit tests should provide rather detailed information about
the methods and their limitations.

The source release provides a *setup.py* script,
which can be used to run the unit tests included.

Source code is available at `<https://github.com/gweis/isodate>`_.


CHANGES
=======

0.7.3 (unreleased)
------------------

- no changes yet


0.7.2 (2024-10-08)
------------------

- drop end of life python versions
- Don't match garbage characters at the end of parsed strings #16 (Gabriel de Perthuis)


Potentially breaking changes:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- Fractional seconds are cut off to microseconds (always round down)
- Allow control over return type of parse_duration #64 (Felix Claessen)
- Python >= 3.7 required


0.6.1 (2021-12-13)
------------------

- support python 3.10 (Hugo van Kemenade)
- last version to support py 2.7


0.6.0 (2017-10-13)
------------------

- support incomplete month date (Fabien Loffredo)
- rely on duck typing when doing duration maths
- support ':' as separator in fractional time zones (usrenmae)


0.5.4 (2015-08-06)
------------------

- Fix parsing of Periods (Fabien Bochu)
- Make Duration objects hashable (Geoffrey Fairchild)
- Add multiplication to duration (Reinoud Elhorst)


0.5.1 (2014-11-07)
------------------

- fixed pickling of Duration objects
- raise ISO8601Error when there is no 'T' separator in datetime strings (Adrian Coveney)


0.5.0 (2014-02-23)
------------------

- ISO8601Error are subclasses of ValueError now (Michael Hrivnak)
- improve compatibility across various python variants and versions
- raise exceptions when using fractional years and months in date
  maths with durations
- renamed method todatetime on Duraction objects to totimedelta


0.4.9 (2012-10-30)
------------------

- support pickling FixedOffset instances
- make sure parsed fractional seconds are in microseconds
- add leading zeros when formattig microseconds (Jarom Loveridge)


0.4.8 (2012-05-04)
------------------

- fixed incompatibility of unittests with python 2.5 and 2.6 (runs fine on 2.7
  and 3.2)


0.4.7 (2012-01-26)
------------------

- fixed tzinfo formatting (never pass None into tzinfo.utcoffset())


0.4.6 (2012-01-06)
------------------

- added Python 3 compatibility via 2to3

0.4.5 (2012-01-06)
------------------

- made setuptools dependency optional

0.4.4 (2011-04-16)
------------------

- Fixed formatting of microseconds for datetime objects

0.4.3 (2010-10-29)
------------------

- Fixed problem with %P formatting and fractions (supplied by David Brooks)

0.4.2 (2010-10-28)
------------------

- Implemented unary - for Duration (supplied by David Brooks)
- Output fractional seconds with '%P' format. (partly supplied by David Brooks)

0.4.1 (2010-10-13)
------------------

- fixed bug in comparison between timedelta and Duration.
- fixed precision problem with microseconds (reported by Tommi Virtanen)

0.4.0 (2009-02-09)
------------------

- added method to parse ISO 8601 time zone strings
- added methods to create ISO 8601 conforming strings

0.3.0 (2009-1-05)
------------------

- Initial release


TODOs
=====

This to do list contains some thoughts and ideas about missing features, and
parts to think about, whether to implement them or not. This list is probably
not complete.

Missing features:
-----------------

    * time formatting does not allow to create fractional representations.
    * parser for ISO intervals.
    * currently microseconds are always padded to a length of 6 characters.
      trailing 0s should be optional

Documentation:
--------------

    * parse_datetime:
       - complete documentation to show what this function allows, but ISO forbids.
         and vice verse.
       - support other separators between date and time than 'T'

    * parse_date:
       - yeardigits should be always greater than 4
       - dates before 0001-01-01 are not supported

    * parse_duration:
       - alternative formats are not fully supported due to parse_date restrictions
       - standard duration format is fully supported but not very restrictive.

    * Duration:
       - support fractional years and month in calculations
       - implement w3c order relation? (`<http://www.w3.org/TR/xmlschema-2/#duration-order>`_)
       - refactor to have duration mathematics only at one place.
       - localize __str__ method (does timedelta do this?)
       - when is a Duration negative?
       - normalize Durations. months [00-12] and years ]-inf,+inf[

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "isodate",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": null,
    "author": "Gerhard Weis",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/54/4d/e940025e2ce31a8ce1202635910747e5a87cc3a6a6bb2d00973375014749/isodate-0.7.2.tar.gz",
    "platform": null,
    "description": "\nISO 8601 date/time parser\n=========================\n\n.. image:: https://travis-ci.org/gweis/isodate.svg?branch=master\n    :target: https://travis-ci.org/gweis/isodate\n    :alt: Travis-CI\n.. image:: https://coveralls.io/repos/gweis/isodate/badge.svg?branch=master\n    :target: https://coveralls.io/r/gweis/isodate?branch=master\n    :alt: Coveralls\n.. image:: https://img.shields.io/pypi/v/isodate.svg\n    :target: https://pypi.python.org/pypi/isodate/\n    :alt: Latest Version\n.. image:: https://img.shields.io/pypi/l/isodate.svg\n    :target: https://pypi.python.org/pypi/isodate/\n    :alt: License\n\n\nThis module implements ISO 8601 date, time and duration parsing.\nThe implementation follows ISO8601:2004 standard, and implements only\ndate/time representations mentioned in the standard. If something is not\nmentioned there, then it is treated as non existent, and not as an allowed\noption.\n\nFor instance, ISO8601:2004 never mentions 2 digit years. So, it is not\nintended by this module to support 2 digit years. (while it may still\nbe valid as ISO date, because it is not explicitly forbidden.)\nAnother example is, when no time zone information is given for a time,\nthen it should be interpreted as local time, and not UTC.\n\nAs this module maps ISO 8601 dates/times to standard Python data types, like\n*date*, *time*, *datetime* and *timedelta*, it is not possible to convert\nall possible ISO 8601 dates/times. For instance, dates before 0001-01-01 are\nnot allowed by the Python *date* and *datetime* classes. Additionally\nfractional seconds are limited to microseconds. That means if the parser finds\nfor instance nanoseconds it will round it down to microseconds.\n\nDocumentation\n-------------\n\nThe following parsing methods are available.\n   * parse_time:\n        parses an ISO 8601 time string into a *time* object\n   * parse_date:\n        parses an ISO 8601 date string into a *date* object\n   * parse_datetime:\n        parses an ISO 8601 date-time string into a *datetime* object\n   * parse_duration:\n        parses an ISO 8601 duration string into a *timedelta* or *Duration*\n        object.\n   * parse_tzinfo:\n        parses the time zone info part of an ISO 8601 string into a\n        *tzinfo* object.\n\nAs ISO 8601 allows to define durations in years and months, and *timedelta*\ndoes not handle years and months, this module provides a *Duration* class,\nwhich can be used almost like a *timedelta* object (with some limitations).\nHowever, a *Duration* object can be converted into a *timedelta* object.\n\nThere are also ISO formatting methods for all supported data types. Each\n*xxx_isoformat* method accepts a format parameter. The default format is\nalways the ISO 8601 expanded format. This is the same format used by\n*datetime.isoformat*:\n\n    * time_isoformat:\n        Intended to create ISO time strings with default format\n        *hh:mm:ssZ*.\n    * date_isoformat:\n        Intended to create ISO date strings with default format\n        *yyyy-mm-dd*.\n    * datetime_isoformat:\n        Intended to create ISO date-time strings with default format\n        *yyyy-mm-ddThh:mm:ssZ*.\n    * duration_isoformat:\n        Intended to create ISO duration strings with default format\n        *PnnYnnMnnDTnnHnnMnnS*.\n    * tz_isoformat:\n        Intended to create ISO time zone strings with default format\n        *hh:mm*.\n    * strftime:\n        A re-implementation mostly compatible with Python's *strftime*, but\n        supports only those format strings, which can also be used for dates\n        prior 1900. This method also understands how to format *datetime* and\n        *Duration* instances.\n\nInstallation\n------------\n\nThis module can easily be installed with Python standard installation methods.\n\nUse *pip install isodate*.\n\nLimitations\n-----------\n\n   * The parser accepts several date/time representation which should be invalid\n     according to ISO 8601 standard.\n\n     1. for date and time together, this parser accepts a mixture of basic and extended format.\n        e.g. the date could be in basic format, while the time is accepted in extended format.\n        It also allows short dates and times in date-time strings.\n     2. For incomplete dates, the first day is chosen. e.g. 19th century results in a date of\n        1901-01-01.\n     3. negative *Duration* and *timedelta* value are not fully supported yet.\n\nFurther information\n-------------------\n\nThe doc strings and unit tests should provide rather detailed information about\nthe methods and their limitations.\n\nThe source release provides a *setup.py* script,\nwhich can be used to run the unit tests included.\n\nSource code is available at `<https://github.com/gweis/isodate>`_.\n\n\nCHANGES\n=======\n\n0.7.3 (unreleased)\n------------------\n\n- no changes yet\n\n\n0.7.2 (2024-10-08)\n------------------\n\n- drop end of life python versions\n- Don't match garbage characters at the end of parsed strings #16 (Gabriel de Perthuis)\n\n\nPotentially breaking changes:\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n- Fractional seconds are cut off to microseconds (always round down)\n- Allow control over return type of parse_duration #64 (Felix Claessen)\n- Python >= 3.7 required\n\n\n0.6.1 (2021-12-13)\n------------------\n\n- support python 3.10 (Hugo van Kemenade)\n- last version to support py 2.7\n\n\n0.6.0 (2017-10-13)\n------------------\n\n- support incomplete month date (Fabien Loffredo)\n- rely on duck typing when doing duration maths\n- support ':' as separator in fractional time zones (usrenmae)\n\n\n0.5.4 (2015-08-06)\n------------------\n\n- Fix parsing of Periods (Fabien Bochu)\n- Make Duration objects hashable (Geoffrey Fairchild)\n- Add multiplication to duration (Reinoud Elhorst)\n\n\n0.5.1 (2014-11-07)\n------------------\n\n- fixed pickling of Duration objects\n- raise ISO8601Error when there is no 'T' separator in datetime strings (Adrian Coveney)\n\n\n0.5.0 (2014-02-23)\n------------------\n\n- ISO8601Error are subclasses of ValueError now (Michael Hrivnak)\n- improve compatibility across various python variants and versions\n- raise exceptions when using fractional years and months in date\n  maths with durations\n- renamed method todatetime on Duraction objects to totimedelta\n\n\n0.4.9 (2012-10-30)\n------------------\n\n- support pickling FixedOffset instances\n- make sure parsed fractional seconds are in microseconds\n- add leading zeros when formattig microseconds (Jarom Loveridge)\n\n\n0.4.8 (2012-05-04)\n------------------\n\n- fixed incompatibility of unittests with python 2.5 and 2.6 (runs fine on 2.7\n  and 3.2)\n\n\n0.4.7 (2012-01-26)\n------------------\n\n- fixed tzinfo formatting (never pass None into tzinfo.utcoffset())\n\n\n0.4.6 (2012-01-06)\n------------------\n\n- added Python 3 compatibility via 2to3\n\n0.4.5 (2012-01-06)\n------------------\n\n- made setuptools dependency optional\n\n0.4.4 (2011-04-16)\n------------------\n\n- Fixed formatting of microseconds for datetime objects\n\n0.4.3 (2010-10-29)\n------------------\n\n- Fixed problem with %P formatting and fractions (supplied by David Brooks)\n\n0.4.2 (2010-10-28)\n------------------\n\n- Implemented unary - for Duration (supplied by David Brooks)\n- Output fractional seconds with '%P' format. (partly supplied by David Brooks)\n\n0.4.1 (2010-10-13)\n------------------\n\n- fixed bug in comparison between timedelta and Duration.\n- fixed precision problem with microseconds (reported by Tommi Virtanen)\n\n0.4.0 (2009-02-09)\n------------------\n\n- added method to parse ISO 8601 time zone strings\n- added methods to create ISO 8601 conforming strings\n\n0.3.0 (2009-1-05)\n------------------\n\n- Initial release\n\n\nTODOs\n=====\n\nThis to do list contains some thoughts and ideas about missing features, and\nparts to think about, whether to implement them or not. This list is probably\nnot complete.\n\nMissing features:\n-----------------\n\n    * time formatting does not allow to create fractional representations.\n    * parser for ISO intervals.\n    * currently microseconds are always padded to a length of 6 characters.\n      trailing 0s should be optional\n\nDocumentation:\n--------------\n\n    * parse_datetime:\n       - complete documentation to show what this function allows, but ISO forbids.\n         and vice verse.\n       - support other separators between date and time than 'T'\n\n    * parse_date:\n       - yeardigits should be always greater than 4\n       - dates before 0001-01-01 are not supported\n\n    * parse_duration:\n       - alternative formats are not fully supported due to parse_date restrictions\n       - standard duration format is fully supported but not very restrictive.\n\n    * Duration:\n       - support fractional years and month in calculations\n       - implement w3c order relation? (`<http://www.w3.org/TR/xmlschema-2/#duration-order>`_)\n       - refactor to have duration mathematics only at one place.\n       - localize __str__ method (does timedelta do this?)\n       - when is a Duration negative?\n       - normalize Durations. months [00-12] and years ]-inf,+inf[\n",
    "bugtrack_url": null,
    "license": "Copyright (c) 2021, Hugo van Kemenade and contributors Copyright (c) 2009-2018, Gerhard Weis and contributors Copyright (c) 2009, Gerhard Weis All rights reserved.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the <organization> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ",
    "summary": "An ISO 8601 date/time/duration parser and formatter",
    "version": "0.7.2",
    "project_urls": {
        "Homepage": "https://github.com/gweis/isodate/"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "15aa0aca39a37d3c7eb941ba736ede56d689e7be91cab5d9ca846bde3999eba6",
                "md5": "f94e527b847362a79a455d0b55134579",
                "sha256": "28009937d8031054830160fce6d409ed342816b543597cece116d966c6d99e15"
            },
            "downloads": -1,
            "filename": "isodate-0.7.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f94e527b847362a79a455d0b55134579",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 22320,
            "upload_time": "2024-10-08T23:04:09",
            "upload_time_iso_8601": "2024-10-08T23:04:09.501382Z",
            "url": "https://files.pythonhosted.org/packages/15/aa/0aca39a37d3c7eb941ba736ede56d689e7be91cab5d9ca846bde3999eba6/isodate-0.7.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "544de940025e2ce31a8ce1202635910747e5a87cc3a6a6bb2d00973375014749",
                "md5": "5ce182fd7f6152cda19ec605b6740687",
                "sha256": "4cd1aa0f43ca76f4a6c6c0292a85f40b35ec2e43e315b59f06e6d32171a953e6"
            },
            "downloads": -1,
            "filename": "isodate-0.7.2.tar.gz",
            "has_sig": false,
            "md5_digest": "5ce182fd7f6152cda19ec605b6740687",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 29705,
            "upload_time": "2024-10-08T23:04:11",
            "upload_time_iso_8601": "2024-10-08T23:04:11.500006Z",
            "url": "https://files.pythonhosted.org/packages/54/4d/e940025e2ce31a8ce1202635910747e5a87cc3a6a6bb2d00973375014749/isodate-0.7.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-08 23:04:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "gweis",
    "github_project": "isodate",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "isodate"
}
        
Elapsed time: 1.79420s