Struct chronoutil::relative_duration::RelativeDuration

source ·
pub struct RelativeDuration { /* private fields */ }
Expand description

Relative time duration extending Chrono’s Duration.

Implementations§

source§

impl RelativeDuration

source

pub fn parse_from_iso8601(input: &str) -> Result<RelativeDuration, String>

Parses an ISO 8601 duration string into a RelativeDuration value.

This supports only duration strings with integer values (i.e "P1Y" but not "P0.5Y" or "P0,5Y"), as fractional values cannot be unambiguously represented as a RelativeDuration. The one exception to this is the seconds field, where the fractional part is truncated to 9 digits, and parsed as nanoseconds.

§Errors
  • Invalid duration string input
  • Fractional values (apart from seconds) in duration string
§Example
use chronoutil::RelativeDuration;

assert_eq!(
    RelativeDuration::parse_from_iso8601("P1Y").unwrap(),
    RelativeDuration::years(1),
);
source

pub fn format_to_iso8601(&self) -> String

Formats a RelativeDuration value into an ISO 8601 duration string.

§Example
use chronoutil::RelativeDuration;

assert_eq!(
    RelativeDuration::years(1).format_to_iso8601(),
    "P1Y",
);
source§

impl RelativeDuration

source

pub fn years(years: i32) -> RelativeDuration

Makes a new RelativeDuration with given number of years.

Equivalent to RelativeDuration::months(years * 12) with overflow checks. Panics when the duration is out of bounds.

source

pub fn months(months: i32) -> RelativeDuration

Makes a new RelativeDuration with given number of months. Panics when the duration is out of bounds.

source

pub fn weeks(weeks: i64) -> RelativeDuration

Makes a new RelativeDuration with given number of weeks. Panics when the duration is out of bounds.

source

pub fn days(days: i64) -> RelativeDuration

Makes a new RelativeDuration with given number of days. Panics when the duration is out of bounds.

source

pub fn hours(hours: i64) -> RelativeDuration

Makes a new RelativeDuration with given number of hours. Panics when the duration is out of bounds.

source

pub fn minutes(minutes: i64) -> RelativeDuration

Makes a new RelativeDuration with given number of minutes. Panics when the duration is out of bounds.

source

pub fn seconds(seconds: i64) -> RelativeDuration

Makes a new RelativeDuration with given number of seconds. Panics when the duration is out of bounds.

source

pub fn milliseconds(milliseconds: i64) -> RelativeDuration

Makes a new RelativeDuration with given number of milliseconds.

source

pub fn microseconds(microseconds: i64) -> RelativeDuration

Makes a new RelativeDuration with given number of microseconds.

source

pub fn nanoseconds(nanos: i64) -> RelativeDuration

Makes a new RelativeDuration with given number of nanoseconds.

source

pub fn with_duration(self, duration: Duration) -> RelativeDuration

Update the Duration part of the current RelativeDuration.

source

pub fn zero() -> RelativeDuration

A RelativeDuration representing zero.

source

pub fn is_zero(&self) -> bool

Returns true if the duration equals RelativeDuration::zero().

Trait Implementations§

source§

impl<Tz> Add<RelativeDuration> for Date<Tz>
where Tz: TimeZone,

§

type Output = Date<Tz>

The resulting type after applying the + operator.
source§

fn add(self, rhs: RelativeDuration) -> Date<Tz>

Performs the + operation. Read more
source§

impl<Tz> Add<RelativeDuration> for DateTime<Tz>
where Tz: TimeZone,

§

type Output = DateTime<Tz>

The resulting type after applying the + operator.
source§

fn add(self, rhs: RelativeDuration) -> DateTime<Tz>

Performs the + operation. Read more
source§

impl Add<RelativeDuration> for NaiveDate

§

type Output = NaiveDate

The resulting type after applying the + operator.
source§

fn add(self, rhs: RelativeDuration) -> NaiveDate

Performs the + operation. Read more
source§

impl Add<RelativeDuration> for NaiveDateTime

§

type Output = NaiveDateTime

The resulting type after applying the + operator.
source§

fn add(self, rhs: RelativeDuration) -> NaiveDateTime

Performs the + operation. Read more
source§

impl Add<RelativeDuration> for Duration

§

type Output = RelativeDuration

The resulting type after applying the + operator.
source§

fn add(self, rhs: RelativeDuration) -> RelativeDuration

Performs the + operation. Read more
source§

impl Add<TimeDelta> for RelativeDuration

§

type Output = RelativeDuration

The resulting type after applying the + operator.
source§

fn add(self, rhs: Duration) -> RelativeDuration

Performs the + operation. Read more
source§

impl Add for RelativeDuration

§

type Output = RelativeDuration

The resulting type after applying the + operator.
source§

fn add(self, rhs: RelativeDuration) -> RelativeDuration

Performs the + operation. Read more
source§

impl Clone for RelativeDuration

source§

fn clone(&self) -> RelativeDuration

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 Debug for RelativeDuration

source§

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

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

impl Div<i32> for RelativeDuration

§

type Output = RelativeDuration

The resulting type after applying the / operator.
source§

fn div(self, rhs: i32) -> RelativeDuration

Performs the / operation. Read more
source§

impl From<Duration> for RelativeDuration

source§

fn from(item: StdDuration) -> Self

Makes a new RelativeDuration from a std Duration.

source§

impl From<TimeDelta> for RelativeDuration

source§

fn from(item: Duration) -> Self

Makes a new RelativeDuration from a chrono::Duration.

source§

impl Hash for RelativeDuration

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Mul<i32> for RelativeDuration

§

type Output = RelativeDuration

The resulting type after applying the * operator.
source§

fn mul(self, rhs: i32) -> RelativeDuration

Performs the * operation. Read more
source§

impl Neg for RelativeDuration

§

type Output = RelativeDuration

The resulting type after applying the - operator.
source§

fn neg(self) -> RelativeDuration

Performs the unary - operation. Read more
source§

impl Ord for RelativeDuration

source§

fn cmp(&self, other: &RelativeDuration) -> 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 RelativeDuration

source§

fn eq(&self, other: &RelativeDuration) -> 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 RelativeDuration

source§

fn partial_cmp(&self, other: &RelativeDuration) -> 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<Tz> Sub<RelativeDuration> for Date<Tz>
where Tz: TimeZone,

§

type Output = Date<Tz>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: RelativeDuration) -> Date<Tz>

Performs the - operation. Read more
source§

impl<Tz> Sub<RelativeDuration> for DateTime<Tz>
where Tz: TimeZone,

§

type Output = DateTime<Tz>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: RelativeDuration) -> DateTime<Tz>

Performs the - operation. Read more
source§

impl Sub<RelativeDuration> for NaiveDate

§

type Output = NaiveDate

The resulting type after applying the - operator.
source§

fn sub(self, rhs: RelativeDuration) -> NaiveDate

Performs the - operation. Read more
source§

impl Sub<RelativeDuration> for NaiveDateTime

§

type Output = NaiveDateTime

The resulting type after applying the - operator.
source§

fn sub(self, rhs: RelativeDuration) -> NaiveDateTime

Performs the - operation. Read more
source§

impl Sub<RelativeDuration> for Duration

§

type Output = RelativeDuration

The resulting type after applying the - operator.
source§

fn sub(self, rhs: RelativeDuration) -> RelativeDuration

Performs the - operation. Read more
source§

impl Sub<TimeDelta> for RelativeDuration

§

type Output = RelativeDuration

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Duration) -> RelativeDuration

Performs the - operation. Read more
source§

impl Sub for RelativeDuration

§

type Output = RelativeDuration

The resulting type after applying the - operator.
source§

fn sub(self, rhs: RelativeDuration) -> RelativeDuration

Performs the - operation. Read more
source§

impl Copy for RelativeDuration

source§

impl Eq for RelativeDuration

source§

impl StructuralPartialEq for RelativeDuration

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.