-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added recipes to documentation. Prepared for release using wheels. Ma…
…ke use of include files for Sphinx documentation. Doctesting for Sphinx documentation. Fixed broken setup.py
- Loading branch information
Showing
10 changed files
with
156 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
recursive-include spans *.py | ||
|
||
include MANIFEST.in LICENSE README.rst Makefile setup.py tox.ini | ||
include MANIFEST.in LICENSE README.rst Makefile setup.py setup.cfg tox.ini doc/*.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.. doctest:: | ||
|
||
>>> from spans import * | ||
>>> from datetime import * | ||
>>> the90s = daterange(date(1990, 1, 1), date(2000, 1, 1)) | ||
>>> date(1996, 12, 4) in the90s | ||
True | ||
>>> date(2000, 1, 1) in the90s | ||
False | ||
>>> the90s.union(daterange(date(2000, 1, 1), date(2010, 1, 1))) | ||
daterange([datetime.date(1990, 1, 1),datetime.date(2010, 1, 1))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
Check if two employees work at the same time | ||
-------------------------------------------- | ||
Spans make working with intervals of time easy. In this example we want to list all hours where `Alice` and `Bob` work at the same time. 24 hour clock is used, as well as weeks starting on Monday. | ||
|
||
.. testcode:: | ||
|
||
import re | ||
from datetime import timedelta | ||
from spans import timedeltarange, timedeltarangeset | ||
|
||
alice = [ | ||
["8-12", "12:30-17"], # Monday | ||
["8-12", "12:30-17"], # Tuesday | ||
["8-12", "12:30-17"], # Wednesday | ||
["8-12", "12:30-17"], # Thursday | ||
["8-12", "12:30-15"], # Friday | ||
["10-14"], # Saturday | ||
[], # Sunday | ||
] | ||
|
||
bob = [ | ||
["15-21"], # Monday | ||
["15-21"], # Tuesday | ||
["15-21"], # Wednesday | ||
["15-21"], # Thursday | ||
["12-18"], # Friday | ||
[], # Saturday | ||
["10-14"], # Sunday | ||
] | ||
|
||
# Convert the data to timedeltarange | ||
def str_to_timedelta_range(string): | ||
# Error handling left as an excersize for the reader | ||
match = re.match( | ||
"^(\d{1,2}):?(\d{1,2})?-(\d{1,2}):?(\d{1,2})?$", string) | ||
|
||
return timedeltarange( | ||
timedelta(hours=int(match.group(1) or 0), minutes=int(match.group(2) or 0)), | ||
timedelta(hours=int(match.group(3) or 0), minutes=int(match.group(4) or 0))) | ||
|
||
schedule_alice = timedeltarangeset( | ||
str_to_timedelta_range(span).offset(timedelta(day)) | ||
for day, spans in enumerate(alice) | ||
for span in spans) | ||
|
||
schedule_bob = timedeltarangeset( | ||
str_to_timedelta_range(span).offset(timedelta(day)) | ||
for day, spans in enumerate(bob) | ||
for span in spans) | ||
|
||
# Print hours where both Alice and Bob work | ||
for span in schedule_alice.intersection(schedule_bob): | ||
print("%-9s %02d:%02d-%02d:%02d" % ( | ||
{ | ||
0: "Monday", | ||
1: "Tuesday", | ||
2: "Wednesday", | ||
3: "Thursday", | ||
4: "Friday", | ||
5: "Saturday", | ||
6: "Sunday", | ||
}[span.lower.days], | ||
span.lower.seconds // 3600, | ||
(span.lower.seconds // 60) % 60, | ||
span.upper.seconds // 3600, | ||
(span.upper.seconds // 60) % 60, | ||
)) | ||
|
||
.. testoutput:: | ||
|
||
Monday 15:00-17:00 | ||
Tuesday 15:00-17:00 | ||
Wednesday 15:00-17:00 | ||
Thursday 15:00-17:00 | ||
Friday 12:30-15:00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Recipes | ||
======= | ||
This is a showcasing of what Spans is capable of. | ||
|
||
.. include:: recipe_overlap.inc.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[bdist_wheel] | ||
universal = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters