worktimecalc


Nameworktimecalc JSON
Version 0.1.4 PyPI version JSON
download
home_page
SummaryCalculates the business time between two datetimes.
upload_time2023-10-31 19:08:25
maintainer
docs_urlNone
authorMisao
requires_python
licenseThe MIT License (MIT) Copyright © 2023 <copyright holders> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords time calculator tools business time business hours work hours work time
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Work Time Calculator
Small tool to calculate the exact business time between two datetimes.

I wasn't happy with the existing tools for their performance, while others only counted the business days. This was built with the goal of being as efficient as possible, easy to use and flexible.

## Features
- Fast! Calculations done in constant time
- Multiple ways to define working hours
- Specific schedule for each day of the week
- Can consider holidays

## Install
```
pip install worktimecalc
```

## Quick example
Just create a calculator and call it to get the difference:
```python
from worktimecalc.calc import WorkTimeCalculator

calc = WorkTimeCalculator(9, 18, 'mon tue thu fri sat')
delta = calc("2050-02-10T10:30:00", "2050-03-10T18:15:00")

print(delta.seconds)    # 675000.0
print(delta.as_dhms)    # {'days': 7, 'hours': 19, 'minutes': 30, 'seconds': 0}
print(delta.as_hms)     # {'hours': 187, 'minutes': 30, 'seconds': 0}
```

## Holidays
Pass it a list of `datetime.date` objects:
```python
holidays = [(2023, 1, 1), (2023, 5, 1), (2023, 11, 1), (2023, 12, 25)]
holidays = [datetime.date(*d) for d in CHILE_HOLIDAYS]
calc = WorkTimeCalculator(10, 18, holidays=holidays)
```

## Constructor examples
```python
calc = WorkTimeCalculator(8, 15)
calc = WorkTimeCalculator(8, 15, '1100100')
calc = WorkTimeCalculator(8, 15, 'sat tue thu mon sun')
calc = WorkTimeCalculator("08:30", "18:30")
calc = WorkTimeCalculator(9, "17:45")
calc = WorkTimeCalculator(datetime.time(8, 30), datetime.time(18, 30))
calc = WorkTimeCalculator(detail=[(8, 16), (8, 16), (8, 16), (8, 16), (8, 10), None, None])
calc = WorkTimeCalculator(detail=[(8, "16:30"), ("17:15", 20), None, None, None, None, None])
```
When in doubt simply check the descriptions for each argument.

## To do
- Overnight shifts (spanning two days)
- Small performance improvements (minmaxing)
- Allow passing holidays as list of tuples

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "worktimecalc",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "time,calculator,tools,business time,business hours,work hours,work time",
    "author": "Misao",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/f9/9c/bcb68069c476c827c2b4493f20e6f5b5eac3bfef56fe9b399fec5e35dbe5/worktimecalc-0.1.4.tar.gz",
    "platform": null,
    "description": "# Work Time Calculator\r\nSmall tool to calculate the exact business time between two datetimes.\r\n\r\nI wasn't happy with the existing tools for their performance, while others only counted the business days. This was built with the goal of being as efficient as possible, easy to use and flexible.\r\n\r\n## Features\r\n- Fast! Calculations done in constant time\r\n- Multiple ways to define working hours\r\n- Specific schedule for each day of the week\r\n- Can consider holidays\r\n\r\n## Install\r\n```\r\npip install worktimecalc\r\n```\r\n\r\n## Quick example\r\nJust create a calculator and call it to get the difference:\r\n```python\r\nfrom worktimecalc.calc import WorkTimeCalculator\r\n\r\ncalc = WorkTimeCalculator(9, 18, 'mon tue thu fri sat')\r\ndelta = calc(\"2050-02-10T10:30:00\", \"2050-03-10T18:15:00\")\r\n\r\nprint(delta.seconds)    # 675000.0\r\nprint(delta.as_dhms)    # {'days': 7, 'hours': 19, 'minutes': 30, 'seconds': 0}\r\nprint(delta.as_hms)     # {'hours': 187, 'minutes': 30, 'seconds': 0}\r\n```\r\n\r\n## Holidays\r\nPass it a list of `datetime.date` objects:\r\n```python\r\nholidays = [(2023, 1, 1), (2023, 5, 1), (2023, 11, 1), (2023, 12, 25)]\r\nholidays = [datetime.date(*d) for d in CHILE_HOLIDAYS]\r\ncalc = WorkTimeCalculator(10, 18, holidays=holidays)\r\n```\r\n\r\n## Constructor examples\r\n```python\r\ncalc = WorkTimeCalculator(8, 15)\r\ncalc = WorkTimeCalculator(8, 15, '1100100')\r\ncalc = WorkTimeCalculator(8, 15, 'sat tue thu mon sun')\r\ncalc = WorkTimeCalculator(\"08:30\", \"18:30\")\r\ncalc = WorkTimeCalculator(9, \"17:45\")\r\ncalc = WorkTimeCalculator(datetime.time(8, 30), datetime.time(18, 30))\r\ncalc = WorkTimeCalculator(detail=[(8, 16), (8, 16), (8, 16), (8, 16), (8, 10), None, None])\r\ncalc = WorkTimeCalculator(detail=[(8, \"16:30\"), (\"17:15\", 20), None, None, None, None, None])\r\n```\r\nWhen in doubt simply check the descriptions for each argument.\r\n\r\n## To do\r\n- Overnight shifts (spanning two days)\r\n- Small performance improvements (minmaxing)\r\n- Allow passing holidays as list of tuples\r\n",
    "bugtrack_url": null,
    "license": "The MIT License (MIT) Copyright \u00a9 2023 <copyright holders>  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \u201cSoftware\u201d), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \u201cAS IS\u201d, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Calculates the business time between two datetimes.",
    "version": "0.1.4",
    "project_urls": {
        "Home": "https://github.com/MisaoDev/work-time-calc"
    },
    "split_keywords": [
        "time",
        "calculator",
        "tools",
        "business time",
        "business hours",
        "work hours",
        "work time"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "670adabacf06ae5aab163cb72dfbafa73c8af41a62aa6badcabbb86efd4a6e16",
                "md5": "8ef5ad6ae3874278ebfbf6b73f175fdc",
                "sha256": "5910851afb0fd857e550fd475970979e8ff681249062c19259d88ad1f74e5501"
            },
            "downloads": -1,
            "filename": "worktimecalc-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8ef5ad6ae3874278ebfbf6b73f175fdc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 7562,
            "upload_time": "2023-10-31T19:08:24",
            "upload_time_iso_8601": "2023-10-31T19:08:24.387568Z",
            "url": "https://files.pythonhosted.org/packages/67/0a/dabacf06ae5aab163cb72dfbafa73c8af41a62aa6badcabbb86efd4a6e16/worktimecalc-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f99cbcb68069c476c827c2b4493f20e6f5b5eac3bfef56fe9b399fec5e35dbe5",
                "md5": "3fa6e3aaad8e6cb90e429330727fb1eb",
                "sha256": "d8e2643848d8846bf55d45ebab565bae8864aa73b9f1c88b1b554990a9f98871"
            },
            "downloads": -1,
            "filename": "worktimecalc-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "3fa6e3aaad8e6cb90e429330727fb1eb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8667,
            "upload_time": "2023-10-31T19:08:25",
            "upload_time_iso_8601": "2023-10-31T19:08:25.941097Z",
            "url": "https://files.pythonhosted.org/packages/f9/9c/bcb68069c476c827c2b4493f20e6f5b5eac3bfef56fe9b399fec5e35dbe5/worktimecalc-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-31 19:08:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "MisaoDev",
    "github_project": "work-time-calc",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "worktimecalc"
}
        
Elapsed time: 4.09031s