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

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.

source

pub fn today() -> TimeType

Alias for TimeType::moment(chrono::offset::Local::now().naive_local())

source

pub fn is_a_amount(&self) -> bool

source

pub fn is_moment(&self) -> bool

source

pub fn is_addition(&self) -> bool

source

pub fn is_subtraction(&self) -> bool

source

pub fn seconds(i: i64) -> TimeType

source

pub fn minutes(i: i64) -> TimeType

source

pub fn hours(i: i64) -> TimeType

source

pub fn days(i: i64) -> TimeType

source

pub fn weeks(i: i64) -> TimeType

Helper for TimeType::days(i * 7)

source

pub fn months(i: i64) -> TimeType

source

pub fn years(i: i64) -> TimeType

source

pub fn moment(ndt: NaiveDateTime) -> TimeType

source

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

source

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

source

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

source

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

source

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

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn get_moment(&self) -> Option<&NaiveDateTime>

source

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.

source

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.

source

pub fn name(&self) -> &'static str

Get a string representation of the variant of the TimeType instance.

source

pub fn calculate(self) -> Result<TimeType>

Trait Implementations§

source§

impl Add for TimeType

§

type Output = TimeType

The resulting type after applying the + operator.
source§

fn add(self, rhs: TimeType) -> Self::Output

Performs the + operation. Read more
source§

impl AddAssign for TimeType

source§

fn add_assign(&mut self, rhs: TimeType)

Performs the += operation. Read more
source§

impl Clone for TimeType

source§

fn clone(&self) -> TimeType

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Daily for TimeType

source§

fn daily(self, i: i64) -> Result<Iter>

source§

impl Debug for TimeType

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Every for TimeType

source§

fn every(self, inc: TT) -> Result<Iter>

source§

impl Hourly for TimeType

source§

fn hourly(self, i: i64) -> Result<Iter>

source§

impl IntoTimeType for TimeType

source§

impl Minutely for TimeType

source§

fn minutely(self, i: i64) -> Result<Iter>

source§

impl Monthly for TimeType

source§

fn monthly(self, i: i64) -> Result<Iter>

source§

impl Ord for TimeType

source§

fn cmp(&self, other: &TimeType) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for TimeType

source§

fn eq(&self, other: &TimeType) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for TimeType

source§

fn partial_cmp(&self, other: &TimeType) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Sub for TimeType

§

type Output = TimeType

The resulting type after applying the - operator.
source§

fn sub(self, rhs: TimeType) -> Self::Output

Performs the - operation. Read more
source§

impl SubAssign for TimeType

source§

fn sub_assign(&mut self, rhs: TimeType)

Performs the -= operation. Read more
source§

impl Weekly for TimeType

source§

fn weekly(self, i: i64) -> Result<Iter>

Conveniance function over Daily::daily( n * 7 )

source§

impl Yearly for TimeType

source§

fn yearly(self, i: i64) -> Result<Iter>

source§

impl Eq for TimeType

source§

impl StructuralPartialEq for TimeType

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.