TimeDelta

Struct TimeDelta 

Source
pub struct TimeDelta {
    pub months: i32,
    pub inner: Duration,
}
Expand description

Represents a duration of time with both months and a more precise duration.

This struct combines a number of months with a chrono::Duration to represent time intervals that may include calendar-specific units (months) as well as fixed-length durations.

§Fields

  • months: The number of months in the time delta.
  • inner: A chrono::Duration representing the precise duration beyond whole months.

§Serialization

When the “serde” feature is enabled, this struct can be serialized and deserialized.

Fields§

§months: i32§inner: Duration

Implementations§

Source§

impl TimeDelta

Source

pub fn parse(duration: &str) -> TResult<Self>

Parse timedelta from string

for example: “2y1mo-3d5h-2m3s” Parses a string representation of a duration into a TimeDelta.

This function supports a variety of time units and can handle complex duration strings.

§Supported Units
  • ns: nanoseconds

  • us: microseconds

  • ms: milliseconds

  • s: seconds

  • m: minutes

  • h: hours

  • d: days

  • w: weeks

  • mo: months

  • y: years

§Format

The duration string should be in the format of <number><unit>, and multiple such pairs can be combined. For example: “2y1mo-3d5h-2m3s” represents 2 years, 1 month, minus 3 days, 5 hours, minus 2 minutes, and 3 seconds.

§Arguments
  • duration - A string slice that holds the duration to be parsed.
§Returns
  • TResult<Self> - A Result containing the parsed TimeDelta if successful, or an error if parsing fails.
§Examples
use tea_time::TimeDelta;

let td = TimeDelta::parse("1y2mo3d4h5m6s").unwrap();
assert_eq!(td.months, 14); // 1 year and 2 months
assert_eq!(td.inner, chrono::Duration::seconds(3 * 86400 + 4 * 3600 + 5 * 60 + 6));
Source

pub const fn nat() -> Self

Source

pub const fn is_nat(&self) -> bool

Source

pub const fn is_not_nat(&self) -> bool

Trait Implementations§

Source§

impl<U: TimeUnitTrait> Add<TimeDelta> for DateTime<U>
where Self: From<DateTime<Utc>> + TryInto<DateTime<Utc>>,

Source§

type Output = DateTime<U>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add<TimeDelta> for Time

Source§

type Output = Time

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add for TimeDelta

Source§

type Output = TimeDelta

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Clone for TimeDelta

Source§

fn clone(&self) -> TimeDelta

Returns a duplicate 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 TimeDelta

Source§

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

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

impl Default for TimeDelta

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Div for TimeDelta

Source§

type Output = i32

The resulting type after applying the / operator.
Source§

fn div(self, rhs: TimeDelta) -> Self::Output

Performs the / operation. Read more
Source§

impl From<&str> for TimeDelta

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Option<TimeDelta>> for TimeDelta

Source§

fn from(duration: Option<Duration>) -> Self

Converts to this type from the input type.
Source§

impl From<Option<i64>> for TimeDelta

Source§

fn from(dt: Option<i64>) -> Self

Converts to this type from the input type.
Source§

impl From<TimeDelta> for TimeDelta

Source§

fn from(duration: Duration) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for TimeDelta

Source§

fn from(dt: i64) -> Self

Converts to this type from the input type.
Source§

impl FromStr for TimeDelta

Source§

type Err = TError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for TimeDelta

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 TimeDelta

Source§

type Output = TimeDelta

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Neg for TimeDelta

Source§

type Output = TimeDelta

The resulting type after applying the - operator.
Source§

fn neg(self) -> TimeDelta

Performs the unary - operation. Read more
Source§

impl PartialEq for TimeDelta

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for TimeDelta

Source§

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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<U: TimeUnitTrait> Sub<TimeDelta> for DateTime<U>
where Self: From<DateTime<Utc>> + TryInto<DateTime<Utc>>,

Source§

type Output = DateTime<U>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub<TimeDelta> for Time

Source§

type Output = Time

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub for TimeDelta

Source§

type Output = TimeDelta

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Copy for TimeDelta

Source§

impl Eq for TimeDelta

Source§

impl StructuralPartialEq for TimeDelta

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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>,

Source§

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>,

Source§

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.