pub struct TimeDelta {
pub months: i32,
pub inner: TimeDelta,
}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: Achrono::Durationrepresenting the precise duration beyond whole months.
§Serialization
When the “serde” feature is enabled, this struct can be serialized and deserialized.
Fields§
§months: i32§inner: TimeDeltaImplementations§
source§impl TimeDelta
impl TimeDelta
sourcepub fn parse(duration: &str) -> Result<TimeDelta, TError>
pub fn parse(duration: &str) -> Result<TimeDelta, TError>
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 parsedTimeDeltaif 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));pub const fn nat() -> TimeDelta
pub const fn is_nat(&self) -> bool
pub const fn is_not_nat(&self) -> bool
Trait Implementations§
source§impl GetDataType for TimeDelta
impl GetDataType for TimeDelta
source§impl IsNone for TimeDelta
impl IsNone for TimeDelta
type Inner = TimeDelta
type Cast<U: IsNone<Inner = U> + Clone> = U
source§fn to_opt(self) -> Option<Self::Inner>
fn to_opt(self) -> Option<Self::Inner>
Option<Self::Inner>. Read moresource§fn as_opt(&self) -> Option<&Self::Inner>
fn as_opt(&self) -> Option<&Self::Inner>
Option<&Self::Inner>. Read moresource§fn from_inner(inner: Self::Inner) -> Self
fn from_inner(inner: Self::Inner) -> Self
Self from the given inner value. Read morefn unwrap(self) -> Self::Inner
source§fn map<F, U: IsNone>(self, f: F) -> U
fn map<F, U: IsNone>(self, f: F) -> U
Self, if it exists. Read moresource§fn from_opt(opt: Option<Self::Inner>) -> Self
fn from_opt(opt: Option<Self::Inner>) -> Self
Self from an Option<Self::Inner>.fn not_none(&self) -> bool
source§fn sort_cmp(&self, other: &Self) -> Orderingwhere
Self::Inner: PartialOrd,
fn sort_cmp(&self, other: &Self) -> Orderingwhere
Self::Inner: PartialOrd,
None as the largest value. Read moresource§fn sort_cmp_rev(&self, other: &Self) -> Orderingwhere
Self::Inner: PartialOrd,
fn sort_cmp_rev(&self, other: &Self) -> Orderingwhere
Self::Inner: PartialOrd,
None as the largest value. Read moresource§impl PartialOrd for TimeDelta
impl PartialOrd for TimeDelta
impl Copy for TimeDelta
impl Eq for TimeDelta
impl StructuralPartialEq for TimeDelta
Auto Trait Implementations§
impl Freeze for TimeDelta
impl RefUnwindSafe for TimeDelta
impl Send for TimeDelta
impl Sync for TimeDelta
impl Unpin for TimeDelta
impl UnwindSafe for TimeDelta
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)