{"id":15637873,"url":"https://github.com/thombashi/datetimerange","last_synced_at":"2025-05-16T03:03:55.535Z","repository":{"id":49879691,"uuid":"52063115","full_name":"thombashi/DateTimeRange","owner":"thombashi","description":"DateTimeRange is a Python library to handle a time range. e.g. check whether a time is within the time range, get the intersection of time ranges, truncate a time range, iterate through a time range, and so forth.","archived":false,"fork":false,"pushed_at":"2024-12-29T12:35:06.000Z","size":368,"stargazers_count":109,"open_issues_count":3,"forks_count":17,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-16T03:03:49.390Z","etag":null,"topics":["datetime","datetime-range","python-library","time-range"],"latest_commit_sha":null,"homepage":"https://datetimerange.rtfd.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thombashi.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"thombashi","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2016-02-19T05:15:09.000Z","updated_at":"2025-02-26T12:38:08.000Z","dependencies_parsed_at":"2023-12-15T02:17:45.436Z","dependency_job_id":"958529f8-1a0e-4478-804f-787f9a5e1852","html_url":"https://github.com/thombashi/DateTimeRange","commit_stats":{"total_commits":473,"total_committers":6,"mean_commits":78.83333333333333,"dds":0.2600422832980972,"last_synced_commit":"17cff0b230134a9277c2ef576e3676ccd7dc6727"},"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thombashi%2FDateTimeRange","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thombashi%2FDateTimeRange/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thombashi%2FDateTimeRange/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thombashi%2FDateTimeRange/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thombashi","download_url":"https://codeload.github.com/thombashi/DateTimeRange/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254459084,"owners_count":22074604,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["datetime","datetime-range","python-library","time-range"],"created_at":"2024-10-03T11:14:00.012Z","updated_at":"2025-05-16T03:03:50.525Z","avatar_url":"https://github.com/thombashi.png","language":"Python","funding_links":["https://github.com/sponsors/thombashi"],"categories":[],"sub_categories":[],"readme":".. contents:: **DateTimeRange**\n   :backlinks: top\n   :depth: 2\n\nSummary\n=========\n`DateTimeRange \u003chttps://github.com/thombashi/DateTimeRange\u003e`__ is a Python library to handle a time range. e.g. check whether a time is within the time range, get the intersection of time ranges, truncate a time range, iterate through a time range, and so forth.\n\n|PyPI pkg ver| |conda pkg ver| |Supported Python ver| |CI status| |Test coverage| |CodeQL|\n\n.. |PyPI pkg ver| image:: https://badge.fury.io/py/DateTimeRange.svg\n    :target: https://badge.fury.io/py/DateTimeRange\n    :alt: PyPI package version\n\n.. |conda pkg ver| image:: https://anaconda.org/conda-forge/datetimerange/badges/version.svg\n    :target: https://anaconda.org/conda-forge/datetimerange\n    :alt: conda-forge package version\n\n.. |Supported Python ver| image:: https://img.shields.io/pypi/pyversions/DateTimeRange.svg\n    :target: https://pypi.org/project/DateTimeRange\n    :alt: Supported Python versions\n\n.. |CI status| image:: https://github.com/thombashi/DateTimeRange/actions/workflows/ci.yml/badge.svg\n    :target: https://github.com/thombashi/DateTimeRange/actions/workflows/ci.yml\n    :alt: CI status of Linux/macOS/Windows\n\n.. |Test coverage| image:: https://coveralls.io/repos/github/thombashi/DateTimeRange/badge.svg?branch=master\n    :target: https://coveralls.io/github/thombashi/DateTimeRange?branch=master\n    :alt: Test coverage\n\n.. |CodeQL| image:: https://github.com/thombashi/DateTimeRange/actions/workflows/github-code-scanning/codeql/badge.svg\n    :target: https://github.com/thombashi/DateTimeRange/actions/workflows/github-code-scanning/codeql\n    :alt: CodeQL\n\nInstallation\n============\n\nInstallation: pip\n------------------------------\n::\n\n    pip install DateTimeRange\n\n\nInstallation: conda\n------------------------------\n::\n\n    conda install -c conda-forge datetimerange\n\n\nDependencies\n============\n- Python 3.9+\n- `Python package dependencies (automatically installed) \u003chttps://github.com/thombashi/DateTimeRange/network/dependencies\u003e`__\n\nFeatures\n============\nFeatures of ``DateTimeRange`` class include:\n\n- Supported operations:\n    - Equation\n    - Addition\n    - Subtraction\n    - Intersection\n    - Union\n    - Contains\n    - Truncate\n    - Split\n    - Iteration\n- Timezone support\n- Daylight saving time support\n\nExamples\n==========\nCreate a DateTimeRange instance from start and end datetime\n-----------------------------------------------------------------\n:Sample Code:\n    .. code:: python\n\n        from datetimerange import DateTimeRange\n        time_range = DateTimeRange(\"2015-03-22T10:00:00+0900\", \"2015-03-22T10:10:00+0900\")\n        str(time_range)\n\n:Output:\n    ::\n\n        '2015-03-22T10:00:00+0900 - 2015-03-22T10:10:00+0900'\n\nCreate a DateTimeRange instance from a range text\n-----------------------------------------------------------------\n:Sample Code:\n    .. code:: python\n\n        from datetimerange import DateTimeRange\n        time_range = DateTimeRange.from_range_text(\"2015-03-22T10:00:00+0900 - 2015-03-22T10:10:00+0900\")\n        str(time_range)\n\n:Output:\n    ::\n\n        '2015-03-22T10:00:00+0900 - 2015-03-22T10:10:00+0900'\n\nGet an iterator\n------------------------\n:Sample Code 1:\n    .. code:: python\n\n        import datetime\n        from datetimerange import DateTimeRange\n\n        time_range = DateTimeRange(\"2015-01-01T00:00:00+0900\", \"2015-01-04T00:00:00+0900\")\n        for value in time_range.range(datetime.timedelta(days=1)):\n            print(value)\n\n:Output 1:\n    ::\n\n        2015-01-01 00:00:00+09:00\n        2015-01-02 00:00:00+09:00\n        2015-01-03 00:00:00+09:00\n        2015-01-04 00:00:00+09:00\n\n:Sample Code 2:\n    .. code:: python\n\n        from datetimerange import DateTimeRange\n        from dateutil.relativedelta import relativedelta\n\n        time_range = DateTimeRange(\"2015-01-01T00:00:00+0900\", \"2016-01-01T00:00:00+0900\")\n        for value in time_range.range(relativedelta(months=+4)):\n            print(value)\n\n:Output 2:\n    ::\n\n        2015-01-01 00:00:00+09:00\n        2015-05-01 00:00:00+09:00\n        2015-09-01 00:00:00+09:00\n        2016-01-01 00:00:00+09:00\n\nTest whether a value within the time range\n------------------------------------------\n:Sample Code:\n    .. code:: python\n\n        from datetimerange import DateTimeRange\n\n        time_range = DateTimeRange(\"2015-03-22T10:00:00+0900\", \"2015-03-22T10:10:00+0900\")\n        print(\"2015-03-22T10:05:00+0900\" in time_range)\n        print(\"2015-03-22T10:15:00+0900\" in time_range)\n\n        time_range_smaller = DateTimeRange(\"2015-03-22T10:03:00+0900\", \"2015-03-22T10:07:00+0900\")\n        print(time_range_smaller in time_range)\n\n:Output:\n    ::\n\n        True\n        False\n        True\n\nTest whether a value intersects the time range\n----------------------------------------------\n:Sample Code:\n    .. code:: python\n\n        from datetimerange import DateTimeRange\n        time_range = DateTimeRange(\"2015-03-22T10:00:00+0900\", \"2015-03-22T10:10:00+0900\")\n        x = DateTimeRange(\"2015-03-22T10:05:00+0900\", \"2015-03-22T10:15:00+0900\")\n        time_range.is_intersection(x)\n\n:Output:\n    ::\n\n        True\n\nMake an intersected time range\n------------------------------\n:Sample Code:\n    .. code:: python\n\n        from datetimerange import DateTimeRange\n        time_range = DateTimeRange(\"2015-03-22T10:00:00+0900\", \"2015-03-22T10:10:00+0900\")\n        x = DateTimeRange(\"2015-03-22T10:05:00+0900\", \"2015-03-22T10:15:00+0900\")\n        time_range.intersection(x)\n\n:Output:\n    ::\n\n        2015-03-22T10:05:00+0900 - 2015-03-22T10:10:00+0900\n\nMake an encompassed time range\n------------------------------\n:Sample Code:\n    .. code:: python\n\n        from datetimerange import DateTimeRange\n        time_range = DateTimeRange(\"2015-03-22T10:00:00+0900\", \"2015-03-22T10:10:00+0900\")\n        x = DateTimeRange(\"2015-03-22T10:05:00+0900\", \"2015-03-22T10:15:00+0900\")\n        time_range.encompass(x)\n\n:Output:\n    ::\n\n        2015-03-22T10:00:00+0900 - 2015-03-22T10:15:00+0900\n\nTruncate time range\n-------------------\n:Sample Code:\n    .. code:: python\n\n        from datetimerange import DateTimeRange\n\n        time_range = DateTimeRange(\"2015-03-22T10:00:00+0900\", \"2015-03-22T10:10:00+0900\")\n        time_range.is_output_elapse = True\n        print(\"before truncate: \", time_range)\n\n        time_range.truncate(10)\n        print(\"after truncate:  \", time_range)\n\n:Output:\n    ::\n\n        before truncate:  2015-03-22T10:00:00+0900 - 2015-03-22T10:10:00+0900 (0:10:00)\n        after truncate:   2015-03-22T10:00:30+0900 - 2015-03-22T10:09:30+0900 (0:09:00)\n\nFor more information\n----------------------\nMore examples are available at \nhttps://datetimerange.rtfd.io/en/latest/pages/examples/index.html\n\nExamples with Jupyter Notebook are also available at `DateTimeRange.ipynb \u003chttps://nbviewer.jupyter.org/github/thombashi/DateTimeRange/tree/master/examples/DateTimeRange.ipynb\u003e`__\n\nDocumentation\n===============\nhttps://datetimerange.rtfd.io/\n\nSponsors\n====================================\n|chasbecker| |shiguredo| |b4tman| |Arturi0| |github|\n\n.. |chasbecker| image:: https://avatars.githubusercontent.com/u/44389260?s=48\u0026u=6da7176e51ae2654bcfd22564772ef8a3bb22318\u0026v=4\n   :target: https://github.com/chasbecker\n   :alt: ex-sponsor: Charles Becker (chasbecker)\n.. |shiguredo| image:: https://avatars.githubusercontent.com/u/2549434?s=48\u0026v=4\n   :target: https://github.com/shiguredo\n   :alt: ex-sponsor: 時雨堂 (shiguredo)\n.. |b4tman| image:: https://avatars.githubusercontent.com/u/3658062?s=48\u0026v=4\n   :target: https://github.com/b4tman\n   :alt: onetime: Dmitry Belyaev (b4tman)\n.. |Arturi0| image:: https://avatars.githubusercontent.com/u/46711571?s=48\u0026u=57687c0e02d5d6e8eeaf9177f7b7af4c9f275eb5\u0026v=4\n   :target: https://github.com/Arturi0\n   :alt: onetime: Arturi0\n.. |github| image:: https://avatars.githubusercontent.com/u/9919?s=48\u0026v=4\n   :target: https://github.com/github\n   :alt: onetime: GitHub (github)\n\n`Become a sponsor \u003chttps://github.com/sponsors/thombashi\u003e`__\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthombashi%2Fdatetimerange","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthombashi%2Fdatetimerange","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthombashi%2Fdatetimerange/lists"}