Skip to main content

Unofficial support for time periods in whenever

Project description

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), where a < b. Used to represent standard clock periods such as [05:00, 07:00).

  • ModularTimePeriod: [a, b), where a > b. Used to represent clock periods that wrap around midnight. For example, [23:00, 04:00).

  • InfiniteTimePeriod: [a, b), where a = 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 TimePeriod ABC class that is designed to be extensible for your TimePeriod requirements. All required methods are defined using multiple dispatch, thanks to the plum library. 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

whenever_time_period-0.0.2.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

whenever_time_period-0.0.2-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file whenever_time_period-0.0.2.tar.gz.

File metadata

  • Download URL: whenever_time_period-0.0.2.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for whenever_time_period-0.0.2.tar.gz
Algorithm Hash digest
SHA256 81dd3495b178aa3f43f09c829c24db9ab75bcf1abb79121ed4c3c42d99ec59bc
MD5 4a1f08ecbf508c7b31ac680bb416aaf8
BLAKE2b-256 11807c42989a4de644b5de6a5f2d6c05a6ee10585660c6e5fe826b0a8366851a

See more details on using hashes here.

File details

Details for the file whenever_time_period-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for whenever_time_period-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 64846cc907f87a7a3993b0d6bb92fac196d65f38a369e414ca905dfd2aae59d1
MD5 4fbdf489e541b77189853b1512cc7e91
BLAKE2b-256 4e3169362e3a3f964bb8c674b55d1ce353d22eae6d32e3ebe9fba58f9710c31d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page