pub trait Trunc: Sized {
    fn trunc_century(self) -> Result<Self, Error>;
fn trunc_year(self) -> Result<Self, Error>;
fn trunc_iso_year(self) -> Result<Self, Error>;
fn trunc_quarter(self) -> Result<Self, Error>;
fn trunc_month(self) -> Result<Self, Error>;
fn trunc_week(self) -> Result<Self, Error>;
fn trunc_iso_week(self) -> Result<Self, Error>;
fn trunc_month_start_week(self) -> Result<Self, Error>;
fn trunc_day(self) -> Result<Self, Error>;
fn trunc_sunday_start_week(self) -> Result<Self, Error>;
fn trunc_hour(self) -> Result<Self, Error>;
fn trunc_minute(self) -> Result<Self, Error>; }
Expand description

Trunc trait for Timestamp/Date/OracleDate

Required methods

Truncates to the first day of the century.

Example
use sqldatetime::{Timestamp, Date, Time, Trunc};

let timestamp = Date::try_from_ymd(2021, 10, 1).unwrap().and_time(Time::ZERO);
let result = Date::try_from_ymd(2001, 1, 1).unwrap().and_time(Time::ZERO);
assert_eq!(timestamp.trunc_century().unwrap(), result);

Truncates to the first day of the year.

Example
use sqldatetime::{Timestamp, Date, Time, Trunc};

let timestamp = Date::try_from_ymd(2021, 10, 1).unwrap().and_time(Time::ZERO);
let result = Date::try_from_ymd(2021, 1, 1).unwrap().and_time(Time::ZERO);
assert_eq!(timestamp.trunc_year().unwrap(), result);

Truncates to the first day of the first week in the year.

Example
use sqldatetime::{Timestamp, Date, Time, Trunc};

let timestamp = Date::try_from_ymd(2021, 10, 1).unwrap().and_time(Time::ZERO);
let result = Date::try_from_ymd(2021, 1, 4).unwrap().and_time(Time::ZERO);
assert_eq!(timestamp.trunc_iso_year().unwrap(), result);

Truncates to the first day of the quarter.

Example
use sqldatetime::{Timestamp, Date, Time, Trunc};

let timestamp = Date::try_from_ymd(2021, 11, 1).unwrap().and_time(Time::ZERO);
let result = Date::try_from_ymd(2021, 10, 1).unwrap().and_time(Time::ZERO);
assert_eq!(timestamp.trunc_quarter().unwrap(), result);

Truncates to the first day of the month.

Example
use sqldatetime::{Timestamp, Date, Time, Trunc};

let timestamp = Date::try_from_ymd(2021, 10, 24).unwrap().and_time(Time::ZERO);
let result = Date::try_from_ymd(2021, 10, 1).unwrap().and_time(Time::ZERO);
assert_eq!(timestamp.trunc_month().unwrap(), result);

Truncates to the same day of the week as the first day of the year.

Example
use sqldatetime::{Timestamp, Date, Time, Trunc};

let timestamp = Date::try_from_ymd(2021, 1, 7).unwrap().and_time(Time::ZERO);
let result = Date::try_from_ymd(2021, 1, 1).unwrap().and_time(Time::ZERO);
assert_eq!(timestamp.trunc_week().unwrap(), result);

Truncates to the monday of the week.

Example
use sqldatetime::{Timestamp, Date, Time, Trunc};

let timestamp = Date::try_from_ymd(2021, 1, 7).unwrap().and_time(Time::ZERO);
let result = Date::try_from_ymd(2021, 1, 4).unwrap().and_time(Time::ZERO);
assert_eq!(timestamp.trunc_iso_week().unwrap(), result);

Truncates to the same day of the week as the first day of the month.

Example
use sqldatetime::{Timestamp, Date, Time, Trunc};

let timestamp = Date::try_from_ymd(2021, 10, 7).unwrap().and_time(Time::ZERO);
let result = Date::try_from_ymd(2021, 10, 1).unwrap().and_time(Time::ZERO);
assert_eq!(timestamp.trunc_month_start_week().unwrap(), result);

Truncates to the day.

Example
use sqldatetime::{Timestamp, Date, Time, Trunc};

let timestamp = Date::try_from_ymd(2021, 10, 1).unwrap().and_time(Time::MAX);
let result = Date::try_from_ymd(2021, 10, 1).unwrap().and_time(Time::ZERO);
assert_eq!(timestamp.trunc_day().unwrap(), result);

Truncates to the sunday of the week.

Example
use sqldatetime::{Timestamp, Date, Time, Trunc};

let timestamp = Date::try_from_ymd(2021, 1, 7).unwrap().and_time(Time::ZERO);
let result = Date::try_from_ymd(2021, 1, 3).unwrap().and_time(Time::ZERO);
assert_eq!(timestamp.trunc_sunday_start_week().unwrap(), result);

Truncates to the hour.

Example
use sqldatetime::{Timestamp, Date, Time, Trunc};

let timestamp = Timestamp::new( Date::try_from_ymd(2021, 1, 1).unwrap(), Time::try_from_hms(9, 59, 59, 59).unwrap());
let result = Timestamp::new( Date::try_from_ymd(2021, 1, 1).unwrap(), Time::try_from_hms(9, 0, 0, 0).unwrap());
assert_eq!(timestamp.trunc_hour().unwrap(), result);

Truncates to the minute.

Example
use sqldatetime::{Timestamp, Date, Time, Trunc};

let timestamp = Timestamp::new( Date::try_from_ymd(2021, 1, 1).unwrap(), Time::try_from_hms(9, 30, 59, 59).unwrap());
let result = Timestamp::new( Date::try_from_ymd(2021, 1, 1).unwrap(), Time::try_from_hms(9, 30, 0, 0).unwrap());
assert_eq!(timestamp.trunc_minute().unwrap(), result);

Implementors