WheneverTimePeriods
An unofficial extension of the whenever library supporting abstract time periods!
Overview
WheneverTimePeriods builds on the whenever library by introducing basic support for TimePeriods -- abstract intervals of the form [a, b), where a and b are whenever.Time clock times.
WheneverTimePeriods introduces support for the following kinds of time periods:
-
LinearTimePeriod:
[a, b), wherea < b. Used to represent standard clock periods such as [05:00, 07:00). -
ModularTimePeriod:
[a, b), wherea > b. Used to represent clock periods that wrap around midnight. For example, [23:00, 04:00). -
InfiniteTimePeriod:
[a, b), wherea = b. Used to represent clock periods that span all possible clock times.
Features
-
Flexible time periods: Handles both standard time periods and time periods that cross midnight or span all clock times.
-
Highly Extensible: We define an abstract
TimePeriodABC class that is designed to be extensible for your TimePeriod requirements. All required methods are defined using multiple dispatch, thanks to theplumlibrary. Adding support for new TimePeriod subclasses is as simple as registering new signatures.
Installation
# TODO Put on pypi
Quickstart
Define a TimePeriod
from whenever import Time
from whenever_time_period import LinearTimePeriod, ModularTimePeriod, InfiniteTimePeriod
linear_period = LinearTimePeriod(Time(3), Time(10))
modular_period = ModularTimePeriod(Time(7), Time(5))
infinite_period = InfiniteTimePeriod(Time(5), Time(5))
"""
For example:
3 5 7 10
| | | |
Linear: [----------------)
Modular: >------) [------->
Infinite: >------[-------------->
"""
Intersections
>> linear_period & modular_period
[LinearTimePeriod[03:00:00, 05:00:00), LinearTimePeriod[07:00:00, 10:00:00)]
"""
3 5 7 10
| | | |
Linear: [----------------)
Modular: >------) [------->
Linear & Modular: [----) [----)
"""
# same as above
>> modular_period & linear_period
LinearTimePeriod[07:00:00, 10:00:00)
>> infinite_period & linear_period
LinearTimePeriod[03:00:00, 10:00:00)
"""
3 5 7 10
| | | |
Infinite: >------[-------------->
Linear: [----------------)
Infinite & Linear: [----------------)
"""
>> infinite_period & modular_period
ModularTimePeriod[07:00:00, 05:00:00)
"""
3 5 7 10
| | | |
Infinite: >------[-------------->
Modular: >------) [------->
Infinite & Modular: >------) [------->
"""
Membership
# TimePeriods are left-closed
>> Time(3) in linear_period
True
# TimePeriods are right-open
>> Time(10) in linear_period
False
# All Times are members of InfiniteTimePeriods
>> Time(7) in infinte_period
True
Contributing
Contributions are welcome. Contributions should be accompanied by a well-documented pull request and appropriate testing.
Metadata
Release files for whenever-time-period 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| whenever_time_period-0.0.2.tar.gz | 16.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| whenever_time_period-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 32.7 kB
Release files / whenever_time_period-0.0.2.tar.gz
| Download URL | whenever_time_period-0.0.2.tar.gz |
|---|---|
| Size | 16.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
81dd3495b178aa3f43f09c829c24db9ab75bcf1abb79121ed4c3c42d99ec59bc
|
|
BLAKE2b-256 checksum How to use checksums |
11807c42989a4de644b5de6a5f2d6c05a6ee10585660c6e5fe826b0a8366851a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.7
|
Release files / whenever_time_period-0.0.2-py3-none-any.whl
| Download URL | whenever_time_period-0.0.2-py3-none-any.whl |
|---|---|
| Size | 16.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
64846cc907f87a7a3993b0d6bb92fac196d65f38a369e414ca905dfd2aae59d1
|
|
BLAKE2b-256 checksum How to use checksums |
4e3169362e3a3f964bb8c674b55d1ce353d22eae6d32e3ebe9fba58f9710c31d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.7
|