pub enum TimeType {
Show 14 variants
Seconds(i64),
Minutes(i64),
Hours(i64),
Days(i64),
Months(i64),
Years(i64),
Moment(NaiveDateTime),
Addition(Box<TimeType>, Box<TimeType>),
Subtraction(Box<TimeType>, Box<TimeType>),
EndOfYear(Box<TimeType>),
EndOfMonth(Box<TimeType>),
EndOfDay(Box<TimeType>),
EndOfHour(Box<TimeType>),
EndOfMinute(Box<TimeType>),
}
Expand description
A Type of Time, currently based on chrono::NaiveDateTime
Variants§
Seconds(i64)
Minutes(i64)
Hours(i64)
Days(i64)
Months(i64)
Years(i64)
Moment(NaiveDateTime)
Addition(Box<TimeType>, Box<TimeType>)
Subtraction(Box<TimeType>, Box<TimeType>)
EndOfYear(Box<TimeType>)
EndOfMonth(Box<TimeType>)
EndOfDay(Box<TimeType>)
EndOfHour(Box<TimeType>)
EndOfMinute(Box<TimeType>)
Implementations§
source§impl TimeType
impl TimeType
The TimeType type
Warning
If the TimeType is larger than the queried type (E.G. querying a “minutes” on a “month”), the following rules are applied:
- 60 Seconds make a Minute
- 60 Minutes make a Hour
- 24 Hours make a Day
- 7 Days make a Week
- 4 Weeks make a Month
- 12 Months make a Year
Whether these may be correct or not in the current year. The return value of the function
is calculated appropriately. So, calling the get_seconds()
function on 5 minutes returns
60 * 5
.
If the TimeType is smaller than the queried type (E.G. querying a “month” on a “minutes”), zero is returned.
Also, if the TimeType is “5 weeks”, querying a month returns 1
, as 5 weeks contain one
full month.
sourcepub fn today() -> TimeType
pub fn today() -> TimeType
Alias for TimeType::moment(::chrono::offset::Local::now().naive_local())
pub fn is_a_amount(&self) -> bool
pub fn is_moment(&self) -> bool
pub fn is_addition(&self) -> bool
pub fn is_subtraction(&self) -> bool
pub fn seconds(i: i64) -> TimeType
pub fn minutes(i: i64) -> TimeType
pub fn hours(i: i64) -> TimeType
pub fn days(i: i64) -> TimeType
pub fn months(i: i64) -> TimeType
pub fn years(i: i64) -> TimeType
pub fn moment(ndt: NaiveDateTime) -> TimeType
sourcepub fn end_of_year(self) -> TimeType
pub fn end_of_year(self) -> TimeType
Calculate the end of the year based on the current TimeType
The end of a year is considered to be the last day of the year, not the last second.
Warning
If the current TimeType does not evaluate to a TimeType::Moment
, calculating the end of
the year will fail
sourcepub fn end_of_month(self) -> TimeType
pub fn end_of_month(self) -> TimeType
Calculate the end of the month based on the current TimeType
The end of a month is considered to be the last day of the month, not the last second.
Warning
If the current TimeType does not evaluate to a TimeType::Moment
, calculating the end of
the month will fail
sourcepub fn end_of_day(self) -> TimeType
pub fn end_of_day(self) -> TimeType
Calculate the end of the day based on the current TimeType
The end of a day is considered the last second of the day
Warning
If the current TimeType does not evaluate to a TimeType::Moment
, calculating the end of
the day will fail
sourcepub fn end_of_hour(self) -> TimeType
pub fn end_of_hour(self) -> TimeType
Calculate the end of the hour based on the current TimeType
The end of a hour is considered the last second of a hour
Warning
If the current TimeType does not evaluate to a TimeType::Moment
, calculating the end of
the hour will fail
sourcepub fn end_of_minute(self) -> TimeType
pub fn end_of_minute(self) -> TimeType
Calculate the end of the minute based on the current TimeType
The end of a minute is considered to be the last second of a minute
Warning
If the current TimeType does not evaluate to a TimeType::Moment
, calculating the end of
the minute will fail
sourcepub fn get_seconds(&self) -> i64
pub fn get_seconds(&self) -> i64
Get the number of seconds, if the TimeType is not a duration type, zero is returned
Warning
If the type is actually a smaller one (eg. calling get_minutes() on a seconds instance) the following rules are applied:
- A minute is 60 seconds
- A hour is 60 minutes
- A day is 24 hours
- A month is 30 days
- A year is 12 months
Which might not be always correct.
sourcepub fn get_minutes(&self) -> i64
pub fn get_minutes(&self) -> i64
Get the number of minutes, if the TimeType is not a duration type, zero is returned
Warning
If the type is actually a smaller one (eg. calling get_minutes() on a seconds instance) the following rules are applied:
- A minute is 60 seconds
- A hour is 60 minutes
- A day is 24 hours
- A month is 30 days
- A year is 12 months
Which might not be always correct.
sourcepub fn get_hours(&self) -> i64
pub fn get_hours(&self) -> i64
Get the number of hours, if the TimeType is not a duration type, zero is returned
Warning
If the type is actually a smaller one (eg. calling get_minutes() on a seconds instance) the following rules are applied:
- A minute is 60 seconds
- A hour is 60 minutes
- A day is 24 hours
- A month is 30 days
- A year is 12 months
Which might not be always correct.
sourcepub fn get_days(&self) -> i64
pub fn get_days(&self) -> i64
Get the number of days, if the TimeType is not a duration type, zero is returned
Warning
If the type is actually a smaller one (eg. calling get_minutes() on a seconds instance) the following rules are applied:
- A minute is 60 seconds
- A hour is 60 minutes
- A day is 24 hours
- A month is 30 days
- A year is 12 months
Which might not be always correct.
sourcepub fn get_months(&self) -> i64
pub fn get_months(&self) -> i64
Get the number of months, if the TimeType is not a duration type, zero is returned
Warning
If the type is actually a smaller one (eg. calling get_minutes() on a seconds instance) the following rules are applied:
- A minute is 60 seconds
- A hour is 60 minutes
- A day is 24 hours
- A month is 30 days
- A year is 12 months
Which might not be always correct.
sourcepub fn get_years(&self) -> i64
pub fn get_years(&self) -> i64
Get the number of years, if the TimeType is not a duration type, zero is returned
Warning
If the type is actually a smaller one (eg. calling get_minutes() on a seconds instance) the following rules are applied:
- A minute is 60 seconds
- A hour is 60 minutes
- A day is 24 hours
- A month is 30 days
- A year is 12 months
Which might not be always correct.
pub fn get_moment(&self) -> Option<&NaiveDateTime>
sourcepub fn is_a(&self, d: Day) -> Result<bool>
pub fn is_a(&self, d: Day) -> Result<bool>
Check whether a TimeType::Moment
is a certain weekday. Returns an error if TimeType is
not a TimeType::Moment
.
sourcepub fn is_in(&self, month: Month) -> Result<bool>
pub fn is_in(&self, month: Month) -> Result<bool>
Check whether a TimeType::Moment
is in a certain month. Returns an error if the TimeType
is not a TimeType::Moment
.
sourcepub fn name(&self) -> &'static str
pub fn name(&self) -> &'static str
Get a string representation of the variant of the TimeType
instance.
pub fn calculate(self) -> Result<TimeType>
Trait Implementations§
source§impl AddAssign<TimeType> for TimeType
impl AddAssign<TimeType> for TimeType
source§fn add_assign(&mut self, rhs: TimeType)
fn add_assign(&mut self, rhs: TimeType)
+=
operation. Read moresource§impl IntoTimeType for TimeType
impl IntoTimeType for TimeType
fn into_timetype(self) -> Result<TimeType>
source§impl Ord for TimeType
impl Ord for TimeType
source§impl PartialOrd<TimeType> for TimeType
impl PartialOrd<TimeType> for TimeType
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl SubAssign<TimeType> for TimeType
impl SubAssign<TimeType> for TimeType
source§fn sub_assign(&mut self, rhs: TimeType)
fn sub_assign(&mut self, rhs: TimeType)
-=
operation. Read more