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: 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: DurationImplementations§
source§impl TimeDelta
impl TimeDelta
sourcepub fn parse(duration: &str) -> TResult<Self>
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 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() -> Self
pub const fn is_nat(&self) -> bool
pub const fn is_not_nat(&self) -> bool
Trait Implementations§
source§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)