{ "info": { "author": "seppemans", "author_email": "", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Office/Business :: Scheduling" ], "description": "# BusinessTimeDelta\nPython's timedelta for business time. This module helps you calculate the exact working time between two datetimes. It supports common scenarios such as custom schedules, holidays, and time zones.\n\n[![Build Status](https://travis-ci.org/seppemans/businesstimedelta.svg?branch=master)](https://travis-ci.org/seppemans/businesstimedelta)\n\n## Installation\nUse pip to install BusinessTimeDelta.\n\n```shell\npip install businesstimedelta\n```\n\n## Example Use\nDefine your business hours\n\n```python\nimport datetime\nimport pytz\nimport businesstimedelta\n\n# Define a working day\nworkday = businesstimedelta.WorkDayRule(\n start_time=datetime.time(9),\n end_time=datetime.time(18),\n working_days=[0, 1, 2, 3, 4])\n\n# Take out the lunch break\nlunchbreak = businesstimedelta.LunchTimeRule(\n start_time=datetime.time(12),\n end_time=datetime.time(13),\n working_days=[0, 1, 2, 3, 4])\n\n# Combine the two\nbusinesshrs = businesstimedelta.Rules([workday, lunchbreak])\n```\n\nCalculate the business time between two datetimes\n\n```python\nstart = datetime.datetime(2016, 1, 18, 9, 0, 0)\nend = datetime.datetime(2016, 1, 22, 18, 0, 0)\nbdiff = businesshrs.difference(start, end)\n\nprint bdiff\n# \n\nprint \"%s hours and %s seconds\" % (bdiff.hours, bdiff.seconds)\n# 40 hours and 0 seconds\n```\n\nBusiness time arithmetic\n\n```python\nprint start + businesstimedelta.BusinessTimeDelta(businesshrs, hours=40)\n# 2016-01-22 18:00:00+00:00\n\nprint end - businesstimedelta.BusinessTimeDelta(businesshrs, hours=40)\n# 2016-01-18 09:00:00+00:00\n```\n\nTo define holidays, simply use the [Holidays](https://pypi.python.org/pypi/holidays) package\n\n```python\nimport holidays as pyholidays\n\nca_holidays = pyholidays.US(state='CA')\nholidays = businesstimedelta.HolidayRule(ca_holidays)\nbusinesshrs = businesstimedelta.Rules([workday, lunchbreak, holidays])\n\n# Christmas is on Friday 2015/12/25\nstart = datetime.datetime(2015, 12, 21, 9, 0, 0)\nend = datetime.datetime(2015, 12, 28, 9, 0, 0)\nprint businesshrs.difference(start, end)\n# \n```\n\n## Timezones\nIf your datetimes are not timezone aware, they will be localized to UTC (see example above).\n\nLet's say you want to calculate the business time overlap between a working day in San Francisco and in Santiago, Chile:\n```python\nsantiago_workday = businesstimedelta.WorkDayRule(\n start_time=datetime.time(9),\n end_time=datetime.time(18),\n working_days=[0, 1, 2, 3, 4],\n tz=pytz.timezone('America/Santiago'))\n\nsantiago_lunchbreak = businesstimedelta.LunchTimeRule(\n start_time=datetime.time(12),\n end_time=datetime.time(13),\n working_days=[0, 1, 2, 3, 4],\n tz=pytz.timezone('America/Santiago'))\n\nsantiago_businesshrs = businesstimedelta.Rules([santiago_workday, santiago_lunchbreak])\n\nsf_tz = pytz.timezone('America/Los_Angeles')\nsf_start = sf_tz.localize(datetime.datetime(2016, 1, 18, 9, 0, 0))\nsf_end = sf_tz.localize(datetime.datetime(2016, 1, 18, 18, 0, 0))\n\nprint santiago_businesshrs.difference(sf_start, sf_end)\n# \n```\n\n## Overnight Shifts\n```python\n# Day shift\nworkday = WorkDayRule(\n start_time=datetime.time(9),\n end_time=datetime.time(17),\n working_days=[0, 1, 2, 3, 4],\n tz=pytz.utc)\n\n# Night shift\nnightshift = businesstimedelta.WorkDayRule(\n start_time=datetime.time(23),\n end_time=datetime.time(7),\n working_days=[0, 1, 2, 3, 4])\n\nbusinesshrs = businesstimedelta.Rules([workday, nightshift])\n\nstart = datetime.datetime(2016, 1, 18, 9, 0, 0)\nend = datetime.datetime(2016, 1, 22, 18, 0, 0)\nbdiff = businesshrs.difference(start, end)\n\nprint bdiff\n# \n```\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/seppemans/businesstimedelta", "keywords": "business working time timedelta hours businesstime businesshours", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "businesstimedelta", "package_url": "https://pypi.org/project/businesstimedelta/", "platform": "", "project_url": "https://pypi.org/project/businesstimedelta/", "project_urls": { "Homepage": "http://github.com/seppemans/businesstimedelta" }, "release_url": "https://pypi.org/project/businesstimedelta/1.0.1/", "requires_dist": [ "pytz", "holidays" ], "requires_python": "", "summary": "Timedelta for business time. Supports exact amounts of time (hours, seconds), custom schedules, holidays, and time zones.", "version": "1.0.1" }, "last_serial": 5796785, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "361aa30e570632be8db4a9a3499c463c", "sha256": "ea90f885f5c5c0568d7ffdd0bbb2e47147f9f885997ed0bf92d00bf8094f906a" }, "downloads": -1, "filename": "businesstimedelta-0.1.tar.gz", "has_sig": false, "md5_digest": "361aa30e570632be8db4a9a3499c463c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4925, "upload_time": "2016-01-26T00:41:51", "url": "https://files.pythonhosted.org/packages/06/09/b2b8ca37b2ce4e2ae8f3dd3a1a9ecf5baabf4ebf078859b0bf6f0c4ec285/businesstimedelta-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "21e83963bbd81d27c56f61791db9fb46", "sha256": "91e7f9c9d340eb1040f4c1f38fcbf33102956a65ece1e6fd4b2ba17a56563ba4" }, "downloads": -1, "filename": "businesstimedelta-0.2.tar.gz", "has_sig": false, "md5_digest": "21e83963bbd81d27c56f61791db9fb46", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5167, "upload_time": "2016-08-25T23:33:26", "url": "https://files.pythonhosted.org/packages/c9/9e/41758c608aae3ce6d985130f45a5c2353820ef8af10242d11b869a2f174e/businesstimedelta-0.2.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "24e417314dafd66f15c935d8000b1b9a", "sha256": "3c90ecfc1e11c3493fd3dfebb0b35e998f29d45ea3ad54cbec5dc2c78ebc70d5" }, "downloads": -1, "filename": "businesstimedelta-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "24e417314dafd66f15c935d8000b1b9a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8582, "upload_time": "2019-09-07T17:27:07", "url": "https://files.pythonhosted.org/packages/93/bd/509890e3652e713186638b4784f6f325392ce8699ed1c16ddac5ffc20f11/businesstimedelta-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9216818cc3513bce93ea940ecb88d78e", "sha256": "93f41276f7a05592a8d6aa1e20ae0c013d504e6f346bfc433df2ac6ca65f03b4" }, "downloads": -1, "filename": "businesstimedelta-1.0.1.tar.gz", "has_sig": false, "md5_digest": "9216818cc3513bce93ea940ecb88d78e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5780, "upload_time": "2019-09-07T17:27:09", "url": "https://files.pythonhosted.org/packages/55/cd/b7d60a91db23d2de3e7e3e915949dbf4e4ddd02ea2a6b8b8ed27ce9adfac/businesstimedelta-1.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "24e417314dafd66f15c935d8000b1b9a", "sha256": "3c90ecfc1e11c3493fd3dfebb0b35e998f29d45ea3ad54cbec5dc2c78ebc70d5" }, "downloads": -1, "filename": "businesstimedelta-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "24e417314dafd66f15c935d8000b1b9a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8582, "upload_time": "2019-09-07T17:27:07", "url": "https://files.pythonhosted.org/packages/93/bd/509890e3652e713186638b4784f6f325392ce8699ed1c16ddac5ffc20f11/businesstimedelta-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9216818cc3513bce93ea940ecb88d78e", "sha256": "93f41276f7a05592a8d6aa1e20ae0c013d504e6f346bfc433df2ac6ca65f03b4" }, "downloads": -1, "filename": "businesstimedelta-1.0.1.tar.gz", "has_sig": false, "md5_digest": "9216818cc3513bce93ea940ecb88d78e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5780, "upload_time": "2019-09-07T17:27:09", "url": "https://files.pythonhosted.org/packages/55/cd/b7d60a91db23d2de3e7e3e915949dbf4e4ddd02ea2a6b8b8ed27ce9adfac/businesstimedelta-1.0.1.tar.gz" } ] }