Core Concepts
Since When-Exactly allows developers to interact with dates and times in a very unique way, it is worth while becoming familiar with some of the lower-level building blocks.
Moment
The Moment
represents, a moment in time. This is analogous to Python's
datetime.datetime class.
Note
The resolution of a moment is limited to a second. If you need more resolution, then when-exactly is probably not the library you need.
Delta
The Delta
is analogous to Python's
`datetime.timedelta,
with extra functionality for deltas of months and years.
Interval
An interval represents a time span. An interval has a start and a stop.
>>> interval = we.Interval(
... start=we.Moment(2025, 2, 14, 12, 0, 0,),
... stop=we.Moment(2025, 2, 14, 12, 30, 0),
... )
>>> str(interval)
'2025-02-14T12:00:00/2025-02-14T12:30:00'
This is the building block of all the custom intervals like Year, Month, etc.
Intervals
Intervals represents a collection of Interval
objects.
It provides all of the standard functionality you would expect a container to have
>>> intervals = we.Intervals([
... we.Day(2023, 1, 5),
... we.Day(2023, 1, 7),
... we.Week(2023, 10),
... ])
>>> intervals[0]
Day(2023, 1, 5)
>>> intervals[0:2]
Intervals([Day(2023, 1, 5), Day(2023, 1, 7)])
>>> we.Week(2023, 10) in intervals
True
>>> for interval in intervals:
... print(interval)
2023-01-05
2023-01-07
2023-W10