seatgeek / businesstime Goto Github PK
View Code? Open in Web Editor NEWA simple python utility for calculating business time aware timedeltas between two datetimes
License: BSD 2-Clause "Simplified" License
A simple python utility for calculating business time aware timedeltas between two datetimes
License: BSD 2-Clause "Simplified" License
When isholiday
is called, the holiday generator is invoked. But the holiday generator maintains a cache, and it assumes that future calls to isholiday
will be in the future (while len(self._holidays) == 0 or dt > self._holidays[-1]
). However, my code iterates backward and breaks this, because the generator is "forward-only".
start = datetime(2015,2,23,hour=16, minute=0)
end = datetime(2015,2,24,hour=14, minute=20)
bt = BusinessTime(weekends=(SAT, SUN), holidays=holidays, \
business_hours=(time(7), time(16)))
business_time = bt.businesstimedelta(start, end)
Output is 7:20:00
start = datetime(2015,2,23,hour=16, minute=1)
Output is 0:00:00
Tested on Python 3.4.0
Currently you can only specify a pair of open and close times which apply on non-weekend, non-holiday days. It'd be useful to have open and close times which vary by day of the week, time of the year, etc.
Also, the concept of weekend days is fairly arbitrary. It probably makes sense to take this extension of the concept of flexible business hours to support days with no business hours, and have that replace the concept of weekends.
pip install businesstime and python setup.py install does not install the holidays submodule.
From opm.gov:
Federal law (5 U.S.C. 6103) establishes the following public holidays for Federal employees. Please note that most Federal employees work on a Monday through Friday schedule. For these employees, when a holiday falls on a nonworkday -- Saturday or Sunday -- the holiday usually is observed on Monday (if the holiday falls on Sunday) or Friday (if the holiday falls on Saturday).
This piece of code returns the wrong time delta:
>>> bt=BusinessTime()
>>> bt.businesstimedelta(datetime(2016, 6, 17, 18), datetime(2016, 6, 20, 18))
datetime.timedelta(0)
The start time is after hours on a Friday at 6pm, while the end time is after hours on the following Monday at 6pm. The correct answer should be datetime.timedelta(1)
, right?
First of all, thank you very much for your work on this library.
I found myself slightly confused when trying to extract business hours from the timedelta result.
>>> d1 = datetime.datetime(2017, 5, 23, 9, 0)
>>> d2 = datetime.datetime(2017, 5, 24, 9, 0)
>>> r = BusinessTime().businesstimedelta(d1, d2)
datetime.timedelta(1)
My immediate thought to extract the business hours (which in this case it's 8) was to call
timedelta.total_seconds()
method on the result, but this will return the equivalent of 24 hours in seconds, not 8 hours - given it has no knowledge of the business_hours in the BusinessTime object.
This experience proved a bit confusing and was wondering if you might be able to suggest a solution to this? Would a PR would be accepted for this sort of functionality?
Hi, i think could be a problem in the Lead-years
https://github.com/seatgeek/businesstime/blob/master/businesstime/holidays/__init__.py#L9
import businesstime
bt = businesstime.BusinessTime((time(9), time(18)), (5, 6), holidays=None)
t = bt.businesstimedelta(datetime.now(), datetime.now() + timedelta(days=1, hours=-4))
#t = bt.businesstimedelta(datetime.now() - timedelta(days=1), datetime.now() + timedelta(days=0, hours=0))
t = bt.businesstimedelta(datetime.now() - timedelta(hours=2), datetime.now() + timedelta(days=1, hours=0))
m = (float(t.days) * 9 * 60 + float(t.seconds) / 60)
h = m / 60
print h
Not working well if the two times are after business with one day of difference. It should return one business day.
Everything breaks with tz-aware datetimes. It would be good to take an optional tzinfo and to cast the datetimes into that TZ automatically.
For example:
>>> bt.businesstimedelta(datetime(2014, 1, 28, 9), datetime(2014, 1, 29, 9))
datetime.timedelta(0, 28800)
Expected output is datetime.timedelta(1)
Could you make Function for add deltatime?
See
https://github.com/ogt/workdays
https://bitbucket.org/bgelineau/python-bizdatetime
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.