pub enum DateTruncField {
Show 13 variants
Microseconds,
Milliseconds,
Second,
Minute,
Hour,
Day,
Week,
Month,
Quarter,
Year,
Decade,
Century,
Millennium,
}Expand description
A unit date_trunc truncates a timestamp, timestamptz or interval to.
Variants§
Microseconds
microseconds, which leaves the value as it is.
Milliseconds
milliseconds, dropping the microseconds of the millisecond.
Second
second.
Minute
minute.
Hour
hour.
Day
day.
Week
week, the Monday that starts the ISO week, which an interval refuses.
Month
month.
Quarter
quarter, the first month of the quarter.
Year
year.
Decade
decade, as timestamp_trunc counts decades, 2020 for 2024 and 11 BC for 2 BC.
Century
century, its first year, 2001 for 2024 and 100 BC for 1 BC.
Millennium
millennium, its first year, 2001 for 2024 and 1000 BC for 1 BC.
Implementations§
Source§impl DateTruncField
impl DateTruncField
Sourcepub fn parse(unit: &str) -> Result<Self, DateTruncError>
pub fn parse(unit: &str) -> Result<Self, DateTruncError>
The unit PostgreSQL’s date_trunc reads from unit, ASCII letters in either case, with
the first ten characters deciding as DecodeUnits compares them.
§Errors
DateTruncError::UnitNotRecognized for text DecodeUnits does not know, and
DateTruncError::UnitNotSupported for the timezone units it knows.
use sql_values::postgres::{DateTruncError, DateTruncField};
assert_eq!(DateTruncField::parse("Hours"), Ok(DateTruncField::Hour));
assert_eq!(DateTruncField::parse("microseconds"), Ok(DateTruncField::Microseconds));
assert_eq!(DateTruncField::parse("epoch"), Err(DateTruncError::UnitNotRecognized));
assert_eq!(DateTruncField::parse("timezone"), Err(DateTruncError::UnitNotSupported));