Skip to main content

calculator duration days from one time to another

Project description

两个时间点间实际工作时间(去除周六日、节假日)

Package Travis License README

两个时间点间实际工作时间(去除周六日、节假日)。 支持 2004年 至 2021年,包括 2020年 的春节延长。

安装

pip install workday-duration

详细使用示例请参考代码tests中的测试用例

样例1:时间段包含周六日

from datetime import datetime

from workday_duration.utils import duration_days


start_datetime = datetime.strptime('2020-07-31 12:0:0',"%Y-%m-%d %H:%M:%S")
end_datetime = datetime.strptime('2020-08-03 12:0:0', "%Y-%m-%d %H:%M:%S")
work_days, total_days = duration_days(start_datetime, end_datetime)  # 区间全部在休息日)
assert 1 == work_days, "8月1号,2号是周六日,所以实际工作时间为1天"
assert total_days == 3, "绝对时间间隔为3天"

样例2:时间区间包含节假日

from datetime import datetime

from workday_duration.utils import duration_days


start_datetime = datetime.strptime('2020-09-30 12:00:00',"%Y-%m-%d %H:%M:%S")
end_datetime = datetime.strptime('2020-10-02 12:00:00', "%Y-%m-%d %H:%M:%S")
work_days, total_days = duration_days(start_datetime, end_datetime) 
assert 0.5 == work_days, "10.1开始为国庆节,所以实际工作时间只有0.5天"
assert total_days == 2

样例3:带时区的时间间隔(自动转为北京时间后计算)

from workday_duration.utils import duration_days2

work_days, total_days = duration_days2('2020-09-30 16:00:00 +0000', '2020-10-02 04:00:00 +0000', '%Y-%m-%d %H:%M:%S %z') 
assert 0 == work_days, "10.1开始为国庆节,所以实际这个区间都在休假"
assert total_days == 1.5

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

workday-duration-1.0.5.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

workday_duration-1.0.5-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file workday-duration-1.0.5.tar.gz.

File metadata

  • Download URL: workday-duration-1.0.5.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.3

File hashes

Hashes for workday-duration-1.0.5.tar.gz
Algorithm Hash digest
SHA256 3d529588231361b37a09d86efb93a89453ee10d083afb505f6b06c7d4de66b9c
MD5 5cc39f35fb5f4de1d2d5b4738b40ac4a
BLAKE2b-256 004b9003918810eae2487983e5793a4803f0cc5f4891983ed111dda6a45ad345

See more details on using hashes here.

File details

Details for the file workday_duration-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: workday_duration-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.3

File hashes

Hashes for workday_duration-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6a4d16f46e6a9011c6990e13b0e505fd5b286c51808f3ba006a6b22c78c49b76
MD5 331d520b65d5f090089447cdbc51578f
BLAKE2b-256 813f2b4475a372c8fc262a82e8e7d0fd4a6f3aea902300b161cb7db4a4e6cb4d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page