Trait sqldatetime::Round
source · [−]pub trait Round: Sized {
fn round_century(self) -> Result<Self, Error>;
fn round_year(self) -> Result<Self, Error>;
fn round_iso_year(self) -> Result<Self, Error>;
fn round_quarter(self) -> Result<Self, Error>;
fn round_month(self) -> Result<Self, Error>;
fn round_week(self) -> Result<Self, Error>;
fn round_iso_week(self) -> Result<Self, Error>;
fn round_month_start_week(self) -> Result<Self, Error>;
fn round_day(self) -> Result<Self, Error>;
fn round_sunday_start_week(self) -> Result<Self, Error>;
fn round_hour(self) -> Result<Self, Error>;
fn round_minute(self) -> Result<Self, Error>;
}
Expand description
Round trait for Timestamp/Date/OracleDate
Required methods
fn round_century(self) -> Result<Self, Error>
fn round_century(self) -> Result<Self, Error>
If year is more than half of century, rounds to the first day of next century, else truncates.
Example
use sqldatetime::{Timestamp, Date, Time, Round};
let timestamp = Date::try_from_ymd(2051, 1, 1).unwrap().and_time(Time::ZERO);
let result = Date::try_from_ymd(2101, 1, 1).unwrap().and_time(Time::ZERO);
assert_eq!(timestamp.round_century().unwrap(), result);
fn round_year(self) -> Result<Self, Error>
fn round_year(self) -> Result<Self, Error>
If month is bigger than June, rounds to the first day of next year, else truncates.
Example
use sqldatetime::{Timestamp, Date, Time, Round};
let timestamp = Date::try_from_ymd(2021, 7, 1).unwrap().and_time(Time::ZERO);
let result = Date::try_from_ymd(2022, 1, 1).unwrap().and_time(Time::ZERO);
assert_eq!(timestamp.round_year().unwrap(), result);
fn round_iso_year(self) -> Result<Self, Error>
fn round_iso_year(self) -> Result<Self, Error>
If month is bigger than June, rounds to the first day of week in next year, else truncates.
Example
use sqldatetime::{Timestamp, Date, Time, Round};
let timestamp = Date::try_from_ymd(2000, 12, 31).unwrap().and_time(Time::ZERO);
let result = Date::try_from_ymd(2001, 1, 1).unwrap().and_time(Time::ZERO);
assert_eq!(timestamp.round_iso_year().unwrap(), result);
fn round_quarter(self) -> Result<Self, Error>
fn round_quarter(self) -> Result<Self, Error>
Rounds up on the sixteenth day of the second month of the quarter, else truncates.
Example
use sqldatetime::{Timestamp, Date, Time, Round};
let timestamp = Date::try_from_ymd(2021, 11, 16).unwrap().and_time(Time::ZERO);
let result = Date::try_from_ymd(2022, 1, 1).unwrap().and_time(Time::ZERO);
assert_eq!(timestamp.round_quarter().unwrap(), result);
fn round_month(self) -> Result<Self, Error>
fn round_month(self) -> Result<Self, Error>
Rounds up on the sixteenth day of each month, else truncates.
Example
use sqldatetime::{Timestamp, Date, Time, Round};
let timestamp = Date::try_from_ymd(2021, 12, 16).unwrap().and_time(Time::ZERO);
let result = Date::try_from_ymd(2022, 1, 1).unwrap().and_time(Time::ZERO);
assert_eq!(timestamp.round_month().unwrap(), result);
fn round_week(self) -> Result<Self, Error>
fn round_week(self) -> Result<Self, Error>
Rounds up on the fifth day of each week, the same day of the week as the first day of the year, else truncates.
Example
use sqldatetime::{Timestamp, Date, Time, Round};
let timestamp = Date::try_from_ymd(2021, 1, 5).unwrap().and_time(Time::ZERO);
let result = Date::try_from_ymd(2021, 1, 8).unwrap().and_time(Time::ZERO);
assert_eq!(timestamp.round_week().unwrap(), result);
fn round_iso_week(self) -> Result<Self, Error>
fn round_iso_week(self) -> Result<Self, Error>
Rounds up on the fifth day of each week, Monday be the first day of week, else truncates.
Example
use sqldatetime::{Timestamp, Date, Time, Round};
let timestamp = Date::try_from_ymd(2021, 1, 8).unwrap().and_time(Time::ZERO);
let result = Date::try_from_ymd(2021, 1, 11).unwrap().and_time(Time::ZERO);
assert_eq!(timestamp.round_iso_week().unwrap(), result);
fn round_month_start_week(self) -> Result<Self, Error>
fn round_month_start_week(self) -> Result<Self, Error>
Rounds up on the fifth day of each week, the same day of the week as the first day of the month, else truncates.
Example
use sqldatetime::{Timestamp, Date, Time, Round};
let timestamp = Date::try_from_ymd(2021, 1, 5).unwrap().and_time(Time::ZERO);
let result = Date::try_from_ymd(2021, 1, 8).unwrap().and_time(Time::ZERO);
assert_eq!(timestamp.round_month_start_week().unwrap(), result);
Rounds up at 12:00 of each day, else truncates.
Example
use sqldatetime::{Timestamp, Date, Time, Round};
let timestamp = Timestamp::new( Date::try_from_ymd(2021, 12, 31).unwrap(), Time::try_from_hms(12, 0, 0, 0).unwrap());
let result = Date::try_from_ymd(2022, 1, 1).unwrap().and_time(Time::ZERO);
assert_eq!(timestamp.round_day().unwrap(), result);
fn round_sunday_start_week(self) -> Result<Self, Error>
fn round_sunday_start_week(self) -> Result<Self, Error>
Rounds up on the fifth day of each week, Sunday be the first day of week, else truncates.
Example
use sqldatetime::{Timestamp, Date, Time, Round};
let timestamp = Date::try_from_ymd(2021, 1, 8).unwrap().and_time(Time::ZERO);
let result = Date::try_from_ymd(2021, 1, 10).unwrap().and_time(Time::ZERO);
assert_eq!(timestamp.round_sunday_start_week().unwrap(), result);
fn round_hour(self) -> Result<Self, Error>
fn round_hour(self) -> Result<Self, Error>
Rounds up at half of each hour, else truncates.
Example
use sqldatetime::{Timestamp, Date, Time, Round};
let timestamp = Timestamp::new( Date::try_from_ymd(2021, 12, 31).unwrap(), Time::try_from_hms(23, 30, 0, 0).unwrap());
let result = Date::try_from_ymd(2022, 1, 1).unwrap().and_time(Time::ZERO);
assert_eq!(timestamp.round_hour().unwrap(), result);
fn round_minute(self) -> Result<Self, Error>
fn round_minute(self) -> Result<Self, Error>
Rounds up at half of each minute, else truncates.
Example
use sqldatetime::{Timestamp, Date, Time, Round};
let timestamp = Timestamp::new( Date::try_from_ymd(2021, 12, 31).unwrap(), Time::try_from_hms(23, 59, 30, 0).unwrap());
let result = Date::try_from_ymd(2022, 1, 1).unwrap().and_time(Time::ZERO);
assert_eq!(timestamp.round_minute().unwrap(), result);