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.
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.
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
impl Temporal
Sourcepub fn logical_type(&self) -> LogicalType
pub fn logical_type(&self) -> LogicalType
The lattice type of this value.
Sourcepub fn parse(ty: &LogicalType, text: &str) -> Option<Temporal>
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.
Sourcepub fn parse_any(text: &str) -> Option<Temporal>
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.
Sourcepub fn parse_sql_interval(
text: &str,
qualifier: &IntervalQualifier,
) -> Option<Temporal>
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.
Sourcepub fn from_parts(ty: &LogicalType, parts: &Parts) -> Option<Temporal>
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.
Sourcepub fn between(
from: Temporal,
to: Temporal,
kind: DurationKind,
) -> Option<Temporal>
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.