(api)= # Main types ```{eval-rst} .. currentmodule:: whenever ``` The `whenever` library provides four main date-time types, each with its own purpose and behavior: ```{eval-rst} .. toctree:: :maxdepth: 1 instant zoned_datetime offset_datetime plain_datetime ``` The available methods differ between these types based on whether they represent {ref}`exact time or local time `: | type | represents exact time? | represents local time? | |-------------------------------|:----------------------:|:----------------------:| | {class}`Instant` | ✅ | ❌ | {class}`ZonedDateTime` | ✅ | ✅ | | {class}`OffsetDateTime` | ✅ | ✅ | | {class}`PlainDateTime` | ❌ | ✅ | ## Exact time methods The exact time classes ({class}`Instant`, {class}`ZonedDateTime`, and {class}`OffsetDateTime`) share several methods for working with exact points in time: | | {class}`Instant` | {class}`ZonedDateTime` | {class}`OffsetDateTime` | |----|:--------:|:-----:|:------:| | `now()` | {meth}`🔗 ` | {meth}`🔗 ` | {meth}`🔗 ` | | | | | | | `timestamp()` [^1] | {meth}`🔗 ` | {meth}`🔗 ` | {meth}`🔗 ` | | `from_timestamp()` [^2] | {meth}`🔗 ` | {meth}`🔗 ` | {meth}`🔗 ` | | | | | | | `to_fixed_offset()` | {meth}`🔗 ` | {meth}`🔗 ` | {meth}`🔗 ` | | `to_tz()` | {meth}`🔗 ` | {meth}`🔗 ` | {meth}`🔗 ` | | `to_system_tz()` | {meth}`🔗 ` | {meth}`🔗 ` | {meth}`🔗 ` | | | | | | | `x > other_exact` [^3] | {meth}`🔗 ` | {meth}`🔗 ` | {meth}`🔗 ` | | `x - other_exact` | {meth}`🔗 ` | {meth}`🔗 ` | {meth}`🔗 ` | | `x == other_exact` | {meth}`🔗 ` | {meth}`🔗 ` | {meth}`🔗 ` | | `exact_eq()` | {meth}`🔗 ` | {meth}`🔗 ` | {meth}`🔗 ` | | | | | | | `x + TimeDelta` | {meth}`🔗 ` | {meth}`🔗 ` | {meth}`🔗 ` | ## Local time methods The local time classes ({class}`PlainDateTime`, {class}`ZonedDateTime`, and {class}`OffsetDateTime`) share several methods for working with local date and time values: | | {class}`PlainDateTime` | {class}`ZonedDateTime` | {class}`OffsetDateTime` | |----|:--------:|:-----:|:------:| | `year`, `month`, etc. | {attr}`🔗 ` | {attr}`🔗 ` | {attr}`🔗 ` | | `hour`, `minute`, etc. | {attr}`🔗 ` | {attr}`🔗 ` | {attr}`🔗 ` | | `date()` | {meth}`🔗 ` | {meth}`🔗 ` | {meth}`🔗 ` | | `time()` | {meth}`🔗 ` | {meth}`🔗 ` | {meth}`🔗 ` | | | | | | `replace()` [^4] | {meth}`🔗 ` | {meth}`🔗 ` | {meth}`🔗 ` | | `add()`, `subtract()` | {meth}`🔗 `, {meth}`🔗 ` | {meth}`🔗 `, {meth}`🔗 ` | {meth}`🔗 `, {meth}`🔗 ` | | `since()`, `until()` | {meth}`🔗 `, {meth}`🔗 ` | {meth}`🔗 `, {meth}`🔗 ` | {meth}`🔗 `, {meth}`🔗 ` | | `round()` | {meth}`🔗 ` | {meth}`🔗 ` | {meth}`🔗 ` | :::{note} Although {class}`Instant`'s debug representation is in UTC, it does not have local time methods. See the {ref}`FAQ ` for more details. ::: ## Other methods Several other methods are unique to one or more classes: | {class}`Instant` | {class}`ZonedDateTime` | {class}`OffsetDateTime` | {class}`PlainDateTime` | |--------------------------------------------|-----------------------------------------|----------------------------------------|-------------------------------------------------------| | {attr}`~Instant.MIN`, {attr}`~Instant.MAX` | | | {attr}`~PlainDateTime.MIN`, {attr}`~PlainDateTime.MAX` | | {meth}`~Instant.from_utc` | | | | | {attr}`~Instant.format_rfc2822` | | {meth}`~OffsetDateTime.format_rfc2822` | | | | {meth}`~ZonedDateTime.to_instant` | {meth}`~OffsetDateTime.to_instant` | | | | {meth}`~ZonedDateTime.to_plain` | {meth}`~OffsetDateTime.to_plain` | | | | {attr}`~ZonedDateTime.offset` | {attr}`~OffsetDateTime.offset` | | | | | | {meth}`x == other_plain ` | | | | | {meth}`x > other_plain ` | | | | | {meth}`x - other_plain ` | | | | | {meth}`~PlainDateTime.assume_utc` | | | | {meth}`~OffsetDateTime.assume_tz` | {meth}`~PlainDateTime.assume_tz` | | | | | {meth}`~PlainDateTime.assume_system_tz` | | | | | {meth}`~PlainDateTime.assume_fixed_offset` | | | | {meth}`~OffsetDateTime.parse_strptime` | {meth}`~PlainDateTime.parse_strptime` | | | {attr}`~ZonedDateTime.tz` | | | | | {meth}`~ZonedDateTime.now_in_system_tz` | | | | | {meth}`~ZonedDateTime.is_ambiguous` | | | | | {meth}`~ZonedDateTime.dst_offset` | | | | | {meth}`~ZonedDateTime.tz_abbrev` | | | | | {meth}`~ZonedDateTime.day_length` | | | | | {meth}`~ZonedDateTime.start_of_day` | | | [^1]: `timestamp_millis()` and `timestamp_nanos()` methods are also available for millisecond and nanosecond precision. [^2]: `from_timestamp_millis()` and `from_timestamp_nanos()` methods are also available for millisecond and nanosecond precision. [^3]: The other comparison operators `<=`, `<`, and `>=` are also supported. [^4]: `replace_date()` and `replace_time()` are also available for replacing only the date or time component.