Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/json2d/timecoach
a utility library for generating chunks of time within a datetime range
https://github.com/json2d/timecoach
Last synced: 27 days ago
JSON representation
a utility library for generating chunks of time within a datetime range
- Host: GitHub
- URL: https://github.com/json2d/timecoach
- Owner: json2d
- License: mit
- Created: 2020-01-29T21:59:29.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-02-07T03:47:13.000Z (almost 5 years ago)
- Last Synced: 2024-11-17T15:24:20.604Z (about 2 months ago)
- Language: Python
- Homepage: https://pypi.org/project/timecoach/
- Size: 10.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ⏳ timecoach
a utility library for generating chunks of **time** within a datetime range## Installation
```bash
pip install timecoach
```## Quick Start
here's how to iterate through chunks of **iso hours** using `timecoach.chunk_hours`:
```py
import timecoach
import datetimestart = datetime.datetime(2020, 1, 11, 12, 30, 0) # 12:30pm on January 11th 2020
end = datetime.timedelta(hours=2) # two hours laterfor chunk_start, chunk_end in timecoach.chunk_hours(start, end)
diff = chunk_end - chunk_start
print("i'm a {} minute time chunk!".format(diff.minutes))# i'm a 30 minute time chunk!
# i'm a 60 minute time chunk!
# i'm a 30 minute time chunk!
```and other common chunk sizes:
```py
timecoach.chunk_seconds(start, end)
timecoach.chunk_minutes(start, end)
timecoach.chunk_hours(start, end)
timecoach.chunk_days(start, end)
timecoach.chunk_months(start, end)
timecoach.chunk_years(start, end)
```to specify a custom chunk size:
```py
timecoach.chunk(start, end, minutes=15) # quarter hours
timecoach.chunk(start, end, hours=12) # half days
timecoach.chunk(start, end, months=3) # quarter years
```there are a few caveat with custom chunk sizes:
- the chunk interval must be divisible by its parent interval
- the chunk interval must be defined with a single interval type
- the chunk interval value must be a non-zero positive integerfor example the following would throw exceptions:
```py
timecoach.chunk(start, end, minutes=13)
# AssertionError: 13 minutes is not divisible by parent interval 1 hours (60 minutes)timecoach.chunk(start, end, hours=1, minutes=15)
# AssertionError: 1 hours 15 minutes does not contain only one interval typetimecoach.chunk(start, end, hour=.25)
# AssertionError: .25 hours is not non-zero positive integer interval valuetimecoach.chunk(start, end, hour=-1)
# AssertionError: .25 hours is not non-zero positive integer interval value```
if your chunk interval type is `year` then sky's the limit since its the highest interval:
```py
timecoach.chunk(start_of_time, now, years=1000000) # every million years since the start of time
```## License
MIT