%global _empty_manifest_terminate_build 0 Name: python-businesstimedelta Version: 1.0.1 Release: 1 Summary: Timedelta for business time. Supports exact amounts of time (hours, seconds), custom schedules, holidays, and time zones. License: MIT URL: http://github.com/seppemans/businesstimedelta Source0: https://mirrors.nju.edu.cn/pypi/web/packages/55/cd/b7d60a91db23d2de3e7e3e915949dbf4e4ddd02ea2a6b8b8ed27ce9adfac/businesstimedelta-1.0.1.tar.gz BuildArch: noarch Requires: python3-pytz Requires: python3-holidays %description # BusinessTimeDelta Python'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. [![Build Status](https://travis-ci.org/seppemans/businesstimedelta.svg?branch=master)](https://travis-ci.org/seppemans/businesstimedelta) ## Installation Use pip to install BusinessTimeDelta. ```shell pip install businesstimedelta ``` ## Example Use Define your business hours ```python import datetime import pytz import businesstimedelta # Define a working day workday = businesstimedelta.WorkDayRule( start_time=datetime.time(9), end_time=datetime.time(18), working_days=[0, 1, 2, 3, 4]) # Take out the lunch break lunchbreak = businesstimedelta.LunchTimeRule( start_time=datetime.time(12), end_time=datetime.time(13), working_days=[0, 1, 2, 3, 4]) # Combine the two businesshrs = businesstimedelta.Rules([workday, lunchbreak]) ``` Calculate the business time between two datetimes ```python start = datetime.datetime(2016, 1, 18, 9, 0, 0) end = datetime.datetime(2016, 1, 22, 18, 0, 0) bdiff = businesshrs.difference(start, end) print bdiff # print "%s hours and %s seconds" % (bdiff.hours, bdiff.seconds) # 40 hours and 0 seconds ``` Business time arithmetic ```python print start + businesstimedelta.BusinessTimeDelta(businesshrs, hours=40) # 2016-01-22 18:00:00+00:00 print end - businesstimedelta.BusinessTimeDelta(businesshrs, hours=40) # 2016-01-18 09:00:00+00:00 ``` To define holidays, simply use the [Holidays](https://pypi.python.org/pypi/holidays) package ```python import holidays as pyholidays ca_holidays = pyholidays.US(state='CA') holidays = businesstimedelta.HolidayRule(ca_holidays) businesshrs = businesstimedelta.Rules([workday, lunchbreak, holidays]) # Christmas is on Friday 2015/12/25 start = datetime.datetime(2015, 12, 21, 9, 0, 0) end = datetime.datetime(2015, 12, 28, 9, 0, 0) print businesshrs.difference(start, end) # ``` ## Timezones If your datetimes are not timezone aware, they will be localized to UTC (see example above). Let's say you want to calculate the business time overlap between a working day in San Francisco and in Santiago, Chile: ```python santiago_workday = businesstimedelta.WorkDayRule( start_time=datetime.time(9), end_time=datetime.time(18), working_days=[0, 1, 2, 3, 4], tz=pytz.timezone('America/Santiago')) santiago_lunchbreak = businesstimedelta.LunchTimeRule( start_time=datetime.time(12), end_time=datetime.time(13), working_days=[0, 1, 2, 3, 4], tz=pytz.timezone('America/Santiago')) santiago_businesshrs = businesstimedelta.Rules([santiago_workday, santiago_lunchbreak]) sf_tz = pytz.timezone('America/Los_Angeles') sf_start = sf_tz.localize(datetime.datetime(2016, 1, 18, 9, 0, 0)) sf_end = sf_tz.localize(datetime.datetime(2016, 1, 18, 18, 0, 0)) print santiago_businesshrs.difference(sf_start, sf_end) # ``` ## Overnight Shifts ```python # Day shift workday = WorkDayRule( start_time=datetime.time(9), end_time=datetime.time(17), working_days=[0, 1, 2, 3, 4], tz=pytz.utc) # Night shift nightshift = businesstimedelta.WorkDayRule( start_time=datetime.time(23), end_time=datetime.time(7), working_days=[0, 1, 2, 3, 4]) businesshrs = businesstimedelta.Rules([workday, nightshift]) start = datetime.datetime(2016, 1, 18, 9, 0, 0) end = datetime.datetime(2016, 1, 22, 18, 0, 0) bdiff = businesshrs.difference(start, end) print bdiff # ``` %package -n python3-businesstimedelta Summary: Timedelta for business time. Supports exact amounts of time (hours, seconds), custom schedules, holidays, and time zones. Provides: python-businesstimedelta BuildRequires: python3-devel BuildRequires: python3-setuptools BuildRequires: python3-pip %description -n python3-businesstimedelta # BusinessTimeDelta Python'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. [![Build Status](https://travis-ci.org/seppemans/businesstimedelta.svg?branch=master)](https://travis-ci.org/seppemans/businesstimedelta) ## Installation Use pip to install BusinessTimeDelta. ```shell pip install businesstimedelta ``` ## Example Use Define your business hours ```python import datetime import pytz import businesstimedelta # Define a working day workday = businesstimedelta.WorkDayRule( start_time=datetime.time(9), end_time=datetime.time(18), working_days=[0, 1, 2, 3, 4]) # Take out the lunch break lunchbreak = businesstimedelta.LunchTimeRule( start_time=datetime.time(12), end_time=datetime.time(13), working_days=[0, 1, 2, 3, 4]) # Combine the two businesshrs = businesstimedelta.Rules([workday, lunchbreak]) ``` Calculate the business time between two datetimes ```python start = datetime.datetime(2016, 1, 18, 9, 0, 0) end = datetime.datetime(2016, 1, 22, 18, 0, 0) bdiff = businesshrs.difference(start, end) print bdiff # print "%s hours and %s seconds" % (bdiff.hours, bdiff.seconds) # 40 hours and 0 seconds ``` Business time arithmetic ```python print start + businesstimedelta.BusinessTimeDelta(businesshrs, hours=40) # 2016-01-22 18:00:00+00:00 print end - businesstimedelta.BusinessTimeDelta(businesshrs, hours=40) # 2016-01-18 09:00:00+00:00 ``` To define holidays, simply use the [Holidays](https://pypi.python.org/pypi/holidays) package ```python import holidays as pyholidays ca_holidays = pyholidays.US(state='CA') holidays = businesstimedelta.HolidayRule(ca_holidays) businesshrs = businesstimedelta.Rules([workday, lunchbreak, holidays]) # Christmas is on Friday 2015/12/25 start = datetime.datetime(2015, 12, 21, 9, 0, 0) end = datetime.datetime(2015, 12, 28, 9, 0, 0) print businesshrs.difference(start, end) # ``` ## Timezones If your datetimes are not timezone aware, they will be localized to UTC (see example above). Let's say you want to calculate the business time overlap between a working day in San Francisco and in Santiago, Chile: ```python santiago_workday = businesstimedelta.WorkDayRule( start_time=datetime.time(9), end_time=datetime.time(18), working_days=[0, 1, 2, 3, 4], tz=pytz.timezone('America/Santiago')) santiago_lunchbreak = businesstimedelta.LunchTimeRule( start_time=datetime.time(12), end_time=datetime.time(13), working_days=[0, 1, 2, 3, 4], tz=pytz.timezone('America/Santiago')) santiago_businesshrs = businesstimedelta.Rules([santiago_workday, santiago_lunchbreak]) sf_tz = pytz.timezone('America/Los_Angeles') sf_start = sf_tz.localize(datetime.datetime(2016, 1, 18, 9, 0, 0)) sf_end = sf_tz.localize(datetime.datetime(2016, 1, 18, 18, 0, 0)) print santiago_businesshrs.difference(sf_start, sf_end) # ``` ## Overnight Shifts ```python # Day shift workday = WorkDayRule( start_time=datetime.time(9), end_time=datetime.time(17), working_days=[0, 1, 2, 3, 4], tz=pytz.utc) # Night shift nightshift = businesstimedelta.WorkDayRule( start_time=datetime.time(23), end_time=datetime.time(7), working_days=[0, 1, 2, 3, 4]) businesshrs = businesstimedelta.Rules([workday, nightshift]) start = datetime.datetime(2016, 1, 18, 9, 0, 0) end = datetime.datetime(2016, 1, 22, 18, 0, 0) bdiff = businesshrs.difference(start, end) print bdiff # ``` %package help Summary: Development documents and examples for businesstimedelta Provides: python3-businesstimedelta-doc %description help # BusinessTimeDelta Python'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. [![Build Status](https://travis-ci.org/seppemans/businesstimedelta.svg?branch=master)](https://travis-ci.org/seppemans/businesstimedelta) ## Installation Use pip to install BusinessTimeDelta. ```shell pip install businesstimedelta ``` ## Example Use Define your business hours ```python import datetime import pytz import businesstimedelta # Define a working day workday = businesstimedelta.WorkDayRule( start_time=datetime.time(9), end_time=datetime.time(18), working_days=[0, 1, 2, 3, 4]) # Take out the lunch break lunchbreak = businesstimedelta.LunchTimeRule( start_time=datetime.time(12), end_time=datetime.time(13), working_days=[0, 1, 2, 3, 4]) # Combine the two businesshrs = businesstimedelta.Rules([workday, lunchbreak]) ``` Calculate the business time between two datetimes ```python start = datetime.datetime(2016, 1, 18, 9, 0, 0) end = datetime.datetime(2016, 1, 22, 18, 0, 0) bdiff = businesshrs.difference(start, end) print bdiff # print "%s hours and %s seconds" % (bdiff.hours, bdiff.seconds) # 40 hours and 0 seconds ``` Business time arithmetic ```python print start + businesstimedelta.BusinessTimeDelta(businesshrs, hours=40) # 2016-01-22 18:00:00+00:00 print end - businesstimedelta.BusinessTimeDelta(businesshrs, hours=40) # 2016-01-18 09:00:00+00:00 ``` To define holidays, simply use the [Holidays](https://pypi.python.org/pypi/holidays) package ```python import holidays as pyholidays ca_holidays = pyholidays.US(state='CA') holidays = businesstimedelta.HolidayRule(ca_holidays) businesshrs = businesstimedelta.Rules([workday, lunchbreak, holidays]) # Christmas is on Friday 2015/12/25 start = datetime.datetime(2015, 12, 21, 9, 0, 0) end = datetime.datetime(2015, 12, 28, 9, 0, 0) print businesshrs.difference(start, end) # ``` ## Timezones If your datetimes are not timezone aware, they will be localized to UTC (see example above). Let's say you want to calculate the business time overlap between a working day in San Francisco and in Santiago, Chile: ```python santiago_workday = businesstimedelta.WorkDayRule( start_time=datetime.time(9), end_time=datetime.time(18), working_days=[0, 1, 2, 3, 4], tz=pytz.timezone('America/Santiago')) santiago_lunchbreak = businesstimedelta.LunchTimeRule( start_time=datetime.time(12), end_time=datetime.time(13), working_days=[0, 1, 2, 3, 4], tz=pytz.timezone('America/Santiago')) santiago_businesshrs = businesstimedelta.Rules([santiago_workday, santiago_lunchbreak]) sf_tz = pytz.timezone('America/Los_Angeles') sf_start = sf_tz.localize(datetime.datetime(2016, 1, 18, 9, 0, 0)) sf_end = sf_tz.localize(datetime.datetime(2016, 1, 18, 18, 0, 0)) print santiago_businesshrs.difference(sf_start, sf_end) # ``` ## Overnight Shifts ```python # Day shift workday = WorkDayRule( start_time=datetime.time(9), end_time=datetime.time(17), working_days=[0, 1, 2, 3, 4], tz=pytz.utc) # Night shift nightshift = businesstimedelta.WorkDayRule( start_time=datetime.time(23), end_time=datetime.time(7), working_days=[0, 1, 2, 3, 4]) businesshrs = businesstimedelta.Rules([workday, nightshift]) start = datetime.datetime(2016, 1, 18, 9, 0, 0) end = datetime.datetime(2016, 1, 22, 18, 0, 0) bdiff = businesshrs.difference(start, end) print bdiff # ``` %prep %autosetup -n businesstimedelta-1.0.1 %build %py3_build %install %py3_install install -d -m755 %{buildroot}/%{_pkgdocdir} if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi pushd %{buildroot} if [ -d usr/lib ]; then find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/lib64 ]; then find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/bin ]; then find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/sbin ]; then find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst fi touch doclist.lst if [ -d usr/share/man ]; then find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst fi popd mv %{buildroot}/filelist.lst . mv %{buildroot}/doclist.lst . %files -n python3-businesstimedelta -f filelist.lst %dir %{python3_sitelib}/* %files help -f doclist.lst %{_docdir}/* %changelog * Wed Apr 12 2023 Python_Bot - 1.0.1-1 - Package Spec generated