calc-work-hours


Namecalc-work-hours JSON
Version 0.2024.2 PyPI version JSON
download
home_page
SummaryGiven two datetimes, calculate the working hours between them.
upload_time2023-11-27 03:00:42
maintainer
docs_urlNone
author
requires_python>=3.11
licenseMIT License Copyright (c) 2023 calc-work-hours Yosef HE 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 work hour workhour working hour workinghour work day workday working day workingday
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Calc Work Hours
计算两个`DateTime`之间,工作时间的长度(小时)。这个工具最初是用来计算任务工时的。给定任务开始时间,任务结束时间,得出任务工时。会刨去中国的法定节假日及周末。因为中国假日每年发布一次,所以这个工具的第二位版本号就是最新支持年份,如:`v0.2023`就是已经更新到2023年节假日及调休。起始年份是2015年。早于2015年的日期,或者晚于版本号日期,只刨去周末。

Calculate the length of work hours between two `DateTime`s. This tool was originally used to calculate task hours. Given the task start time and the task end time, the task hours are calculated. It will exclude China's statutory holidays and weekends. Because China's holidays are released once a year, the second version number of this tool is the latest supported year, such as: `v0.2023` means that it has been updated to 2023 holidays and adjustments. The starting year is 2015. Dates earlier than 2015 or later then the version year will only exclude weekends.


## Install
目前只支持 python 3.11 及更高:

Currently only supports python 3.11 and higher:

`pip311 install calc_work_hours`

## Usage
```python
from work_hours import WorkHours
wh = WorkHours()
```

### 计算两个`datetime`之间的工作时间长度(小时)  
### Calculate the working time duration (hours) between two `datetime`s

``` python
from datetime import datetime

ret = wh.calc(datetime(2023, 9, 22, 1, 1, 1), datetime(2023, 10, 4, 18, 0, 0)) 
print(ret) 
# 40.0 (hours)
```

### 计算`datetime`是否工作日 
### Calculate whether a `datetime` is a working day

``` python
ret = wh.is_workday(datetime(2023, 10, 2))  
print(ret) 
# 周一,但是 False
# Monday, but False

ret = wh.is_workday(datetime(2023, 10, 7))
print(ret) 
# 周六,但是 True
# Saturday, but True
```
### 计算某个`datetime`是否为工作时间,需要动态的考虑边界。比如9:00,如果(某段时间)从9点开始,那9点是工作时间,如果是(某段时间)到9点结束,那么就不是工作时间。
### Calculate whether a `datetime` is working time, you need to dynamically consider the boundary. For example, 9:00, if (a period of time) starts at 9 o'clock, then 9 o'clock is working time, if (a period of time) ends at 9 o'clock, then 9 is not working time.

``` python
is_work = wh.is_workhours(datetime(2023, 9, 22, 9, 0, 0), )
print(is_work)
# True. The time frame starting from 9:00 ~ 

is_work = wh.is_workhours(datetime(2023, 9, 22, 9, 0, 0), False)
print(is_work)
# False. The time frame ending at 9:00 ~ 
```
### 计算`datetime`的下/上n个工作日的时间
### Calculate n working days after/before a certain `datetime`

``` python
dt = wh.add_workdays(datetime(2023, 9, 22), 5)
print(dt)
# 2023-09-28 18:00
```
09-22|09-23|09-24|09-25|09-26|09-27|09-28
-|-|-|-|-|-|-
 fri | sat | sun | mon | tue | wed | thu
 1   |  .. |  .. |  2  |  3  |  4  | 5

``` python
dt = wh.add_workdays(datetime(2023, 9, 22), -5)
print(dt)
# 2023-09-15 09:00
```


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "calc-work-hours",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": "",
    "keywords": "work hour,workhour,working hour,workinghour,work day,workday,working day,workingday",
    "author": "",
    "author_email": "Yosef HE <h7w8@qq.com>",
    "download_url": "https://files.pythonhosted.org/packages/16/00/13968172cfd111467284dad188b1752bf22893c50664e3f282008e82bb9d/calc-work-hours-0.2024.2.tar.gz",
    "platform": null,
    "description": "# Calc Work Hours\r\n\u8ba1\u7b97\u4e24\u4e2a`DateTime`\u4e4b\u95f4\uff0c\u5de5\u4f5c\u65f6\u95f4\u7684\u957f\u5ea6\uff08\u5c0f\u65f6\uff09\u3002\u8fd9\u4e2a\u5de5\u5177\u6700\u521d\u662f\u7528\u6765\u8ba1\u7b97\u4efb\u52a1\u5de5\u65f6\u7684\u3002\u7ed9\u5b9a\u4efb\u52a1\u5f00\u59cb\u65f6\u95f4\uff0c\u4efb\u52a1\u7ed3\u675f\u65f6\u95f4\uff0c\u5f97\u51fa\u4efb\u52a1\u5de5\u65f6\u3002\u4f1a\u5228\u53bb\u4e2d\u56fd\u7684\u6cd5\u5b9a\u8282\u5047\u65e5\u53ca\u5468\u672b\u3002\u56e0\u4e3a\u4e2d\u56fd\u5047\u65e5\u6bcf\u5e74\u53d1\u5e03\u4e00\u6b21\uff0c\u6240\u4ee5\u8fd9\u4e2a\u5de5\u5177\u7684\u7b2c\u4e8c\u4f4d\u7248\u672c\u53f7\u5c31\u662f\u6700\u65b0\u652f\u6301\u5e74\u4efd\uff0c\u5982\uff1a`v0.2023`\u5c31\u662f\u5df2\u7ecf\u66f4\u65b0\u52302023\u5e74\u8282\u5047\u65e5\u53ca\u8c03\u4f11\u3002\u8d77\u59cb\u5e74\u4efd\u662f2015\u5e74\u3002\u65e9\u4e8e2015\u5e74\u7684\u65e5\u671f\uff0c\u6216\u8005\u665a\u4e8e\u7248\u672c\u53f7\u65e5\u671f\uff0c\u53ea\u5228\u53bb\u5468\u672b\u3002\r\n\r\nCalculate the length of work hours between two `DateTime`s. This tool was originally used to calculate task hours. Given the task start time and the task end time, the task hours are calculated. It will exclude China's statutory holidays and weekends. Because China's holidays are released once a year, the second version number of this tool is the latest supported year, such as: `v0.2023` means that it has been updated to 2023 holidays and adjustments. The starting year is 2015. Dates earlier than 2015 or later then the version year will only exclude weekends.\r\n\r\n\r\n## Install\r\n\u76ee\u524d\u53ea\u652f\u6301 python 3.11 \u53ca\u66f4\u9ad8\uff1a\r\n\r\nCurrently only supports python 3.11 and higher:\r\n\r\n`pip311 install calc_work_hours`\r\n\r\n## Usage\r\n```python\r\nfrom work_hours import WorkHours\r\nwh = WorkHours()\r\n```\r\n\r\n### \u8ba1\u7b97\u4e24\u4e2a`datetime`\u4e4b\u95f4\u7684\u5de5\u4f5c\u65f6\u95f4\u957f\u5ea6(\u5c0f\u65f6)  \r\n### Calculate the working time duration (hours) between two `datetime`s\r\n\r\n``` python\r\nfrom datetime import datetime\r\n\r\nret = wh.calc(datetime(2023, 9, 22, 1, 1, 1), datetime(2023, 10, 4, 18, 0, 0)) \r\nprint(ret) \r\n# 40.0 (hours)\r\n```\r\n\r\n### \u8ba1\u7b97`datetime`\u662f\u5426\u5de5\u4f5c\u65e5 \r\n### Calculate whether a `datetime` is a working day\r\n\r\n``` python\r\nret = wh.is_workday(datetime(2023, 10, 2))  \r\nprint(ret) \r\n# \u5468\u4e00\uff0c\u4f46\u662f False\r\n# Monday, but False\r\n\r\nret = wh.is_workday(datetime(2023, 10, 7))\r\nprint(ret) \r\n# \u5468\u516d\uff0c\u4f46\u662f True\r\n# Saturday, but True\r\n```\r\n### \u8ba1\u7b97\u67d0\u4e2a`datetime`\u662f\u5426\u4e3a\u5de5\u4f5c\u65f6\u95f4\uff0c\u9700\u8981\u52a8\u6001\u7684\u8003\u8651\u8fb9\u754c\u3002\u6bd4\u59829:00\uff0c\u5982\u679c\uff08\u67d0\u6bb5\u65f6\u95f4\uff09\u4ece9\u70b9\u5f00\u59cb\uff0c\u90a39\u70b9\u662f\u5de5\u4f5c\u65f6\u95f4\uff0c\u5982\u679c\u662f\uff08\u67d0\u6bb5\u65f6\u95f4\uff09\u52309\u70b9\u7ed3\u675f\uff0c\u90a3\u4e48\u5c31\u4e0d\u662f\u5de5\u4f5c\u65f6\u95f4\u3002\r\n### Calculate whether a `datetime` is working time, you need to dynamically consider the boundary. For example, 9:00, if (a period of time) starts at 9 o'clock, then 9 o'clock is working time, if (a period of time) ends at 9 o'clock, then 9 is not working time.\r\n\r\n``` python\r\nis_work = wh.is_workhours(datetime(2023, 9, 22, 9, 0, 0), )\r\nprint(is_work)\r\n# True. The time frame starting from 9:00 ~ \r\n\r\nis_work = wh.is_workhours(datetime(2023, 9, 22, 9, 0, 0), False)\r\nprint(is_work)\r\n# False. The time frame ending at 9:00 ~ \r\n```\r\n### \u8ba1\u7b97`datetime`\u7684\u4e0b/\u4e0an\u4e2a\u5de5\u4f5c\u65e5\u7684\u65f6\u95f4\r\n### Calculate n working days after/before a certain `datetime`\r\n\r\n``` python\r\ndt = wh.add_workdays(datetime(2023, 9, 22), 5)\r\nprint(dt)\r\n# 2023-09-28 18:00\r\n```\r\n09-22|09-23|09-24|09-25|09-26|09-27|09-28\r\n-|-|-|-|-|-|-\r\n fri | sat | sun | mon | tue | wed | thu\r\n 1   |  .. |  .. |  2  |  3  |  4  | 5\r\n\r\n``` python\r\ndt = wh.add_workdays(datetime(2023, 9, 22), -5)\r\nprint(dt)\r\n# 2023-09-15 09:00\r\n```\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 calc-work-hours Yosef HE  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.",
    "summary": "Given two datetimes, calculate the working hours between them.",
    "version": "0.2024.2",
    "project_urls": {
        "Homepage": "https://github.com/williamxhero/work_hours"
    },
    "split_keywords": [
        "work hour",
        "workhour",
        "working hour",
        "workinghour",
        "work day",
        "workday",
        "working day",
        "workingday"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6b986f9ef7cd826f69f2e2d3f763c9d10789530290f3a0f7b20f42bb9b8a1d91",
                "md5": "57de363f128d10fe7eaafb50bfa74d1f",
                "sha256": "94ae424cd2583b961a072d16a2d1e30a653cbb0775cca3cf3a8e68683934e7db"
            },
            "downloads": -1,
            "filename": "calc_work_hours-0.2024.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "57de363f128d10fe7eaafb50bfa74d1f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 8328,
            "upload_time": "2023-11-27T03:00:40",
            "upload_time_iso_8601": "2023-11-27T03:00:40.340353Z",
            "url": "https://files.pythonhosted.org/packages/6b/98/6f9ef7cd826f69f2e2d3f763c9d10789530290f3a0f7b20f42bb9b8a1d91/calc_work_hours-0.2024.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "160013968172cfd111467284dad188b1752bf22893c50664e3f282008e82bb9d",
                "md5": "0a02fd19b4871d6c64387b305e1f47e0",
                "sha256": "763e9628090182c5627eabdb2a91665dfef58805e883af0a63b58b72eac4e274"
            },
            "downloads": -1,
            "filename": "calc-work-hours-0.2024.2.tar.gz",
            "has_sig": false,
            "md5_digest": "0a02fd19b4871d6c64387b305e1f47e0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 7379,
            "upload_time": "2023-11-27T03:00:42",
            "upload_time_iso_8601": "2023-11-27T03:00:42.416829Z",
            "url": "https://files.pythonhosted.org/packages/16/00/13968172cfd111467284dad188b1752bf22893c50664e3f282008e82bb9d/calc-work-hours-0.2024.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-27 03:00:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "williamxhero",
    "github_project": "work_hours",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "calc-work-hours"
}
        
Elapsed time: 0.24906s