Skip to main content

Temporal

Enum Temporal 

Source
pub enum Temporal {
    Date(i32),
    LocalTime(i64),
    ZonedTime {
        nanos: i64,
        offset: i16,
    },
    LocalDatetime(i64),
    ZonedDatetime {
        nanos: i64,
        offset: i16,
    },
    Duration(DurationKind, i64),
}
Expand description

One temporal value.

The variants carry counts and not fields. A zoned value carries the instant and the offset separately, so two zoned values compare by instant while each still prints in the zone it was written in.

Variants§

§

Date(i32)

Days since 1970-01-01.

§

LocalTime(i64)

Nanoseconds since midnight.

§

ZonedTime

Nanoseconds since midnight in the offset’s own day, and the offset from UTC in minutes.

Fields

§nanos: i64
§offset: i16
§

LocalDatetime(i64)

Nanoseconds since 1970-01-01T00:00:00.

§

ZonedDatetime

Nanoseconds since the epoch in UTC, and the offset from UTC in minutes that the value was written with.

Fields

§nanos: i64
§offset: i16
§

Duration(DurationKind, i64)

Months for a year-month duration, nanoseconds for a day-time one. The kind is carried because the number means nothing on its own.

Implementations§

Source§

impl Temporal

Source

pub fn logical_type(&self) -> LogicalType

The lattice type of this value.

Source

pub fn parse(ty: &LogicalType, text: &str) -> Option<Temporal>

The value text spells as a value of type ty, or None when it spells none.

A datetime type accepts a date on its own, at midnight, because the standard’s datetime literal does. Nothing else is widened: a date is not a datetime and reading one as the other silently would answer a question nobody asked.

Source

pub fn parse_any(text: &str) -> Option<Temporal>

The value text spells when the type is not written out, which is what a property in a fixture and a value read back from a column both need.

The shape decides: a leading P is a duration, a T or a space in the middle is a datetime, a colon is a time, and a dash is a date.

Source

pub fn parse_sql_interval( text: &str, qualifier: &IntervalQualifier, ) -> Option<Temporal>

The duration text spells when it is written the way SQL writes one, INTERVAL '3 04:05:06' DAY TO SECOND, with the qualifier already read.

The qualifier is not decoration. It is the whole of what says how to read the string, because '1-2' is a year and two months under YEAR TO MONTH and is nothing at all under DAY, and '3' is three of whichever single field was named. So this reads the fields the qualifier lists, in order, and refuses anything the qualifier did not ask for.

The leading field is unbounded and the ones behind it are not: '25' HOUR is twenty five hours, and '1 25:00:00' DAY TO SECOND is not a day and an hour, because a written hour that follows a written day has 24 of its own and the standard says so. A number that runs over its field is refused rather than carried, since carrying it would answer a question the statement did not ask.

Source

pub fn from_parts(ty: &LogicalType, parts: &Parts) -> Option<Temporal>

The value a record constructor spells, or None where it spells none.

This is the second way ISO 20.27 and 20.29 write a temporal value: DATE({year: 2024, month: 1, day: 1}) beside DATE('2024-01-01'). A field the record left out takes the least value it has, so DATE({year: 2024}) is the first of January, which is what the standard’s default for an omitted <field> comes to.

None is the calendar refusing, not the record being malformed: the names were checked before anything got here and what is left is a thirteenth month or a thirty-first of February, which the caller reports as 22G06.

Source

pub fn between( from: Temporal, to: Temporal, kind: DurationKind, ) -> Option<Temporal>

The duration from from to to, of the kind asked for, or None when the two are not two instants of one shape or the answer leaves the calendar.

This is what DURATION_BETWEEN answers and what a minus between two instants answers, so the operator and the function cannot drift apart.

The two operands have to be the same shape. A date and a time have no length between them, and a local datetime and a zoned one have none either, because a local value names a wall clock and not an instant, so the length would depend on a zone nobody wrote.

A day-time answer is a count of nanoseconds and needs no calendar. A year-month answer is the largest count of whole months that does not carry from past to, which is stated against zu’s own month addition rather than against a comparison of day numbers. The two readings differ: 31 March to 30 April is one month here, because 31 March plus one month is 30 April and lands exactly on it, and is nought under a rule that compares the days of the month first. Stating it against the addition is what makes from + DURATION_BETWEEN(from, to) land at or before to and one month more overshoot, and a law that holds is worth more than agreement with a rule that does not.

A backwards answer truncates toward nought the same way, so the two directions are not mirror images when a month is clipped.

Trait Implementations§

Source§

impl Clone for Temporal

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Temporal

Source§

impl Debug for Temporal

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Temporal

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Temporal

Source§

impl Hash for Temporal

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Temporal

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Temporal

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.