Skip to main content

TimeSpan

Struct TimeSpan 

Source
pub struct TimeSpan { /* private fields */ }
Expand description

A signed time interval with a resolution of 100 nanoseconds.

Implementations§

Source§

impl TimeSpan

Source

pub const TICKS_PER_MILLISECOND: i64 = 10_000

The number of ticks in one millisecond.

Source

pub const TICKS_PER_SECOND: i64 = 10_000_000

The number of ticks in one second.

Source

pub const TICKS_PER_MINUTE: i64 = 600_000_000

The number of ticks in one minute.

Source

pub const TICKS_PER_HOUR: i64 = 36_000_000_000

The number of ticks in one hour.

Source

pub const TICKS_PER_DAY: i64 = 864_000_000_000

The number of ticks in one day.

Source

pub const ZERO: TimeSpan

The zero interval.

Source

pub const MAX_VALUE: TimeSpan

The largest interval.

Source

pub const MIN_VALUE: TimeSpan

The smallest (most negative) interval.

Source

pub const fn from_ticks(ticks: i64) -> Self

Creates an interval from a number of 100-nanosecond ticks.

Source

pub fn from_seconds(value: f64) -> Self

Creates an interval from a number of seconds, rounded to the nearest tick. Panics if the value is not a number or out of range.

Source

pub fn from_milliseconds(value: f64) -> Self

Creates an interval from a number of milliseconds, rounded to the nearest tick. Panics if the value is not a number or out of range.

Source

pub fn from_minutes(value: f64) -> Self

Creates an interval from a number of minutes.

Source

pub const fn ticks(self) -> i64

The number of ticks.

Source

pub fn total_seconds(self) -> f64

The interval in whole and fractional seconds.

Source

pub fn total_milliseconds(self) -> f64

The interval in whole and fractional milliseconds.

Source

pub fn to_duration(self) -> Option<Duration>

The interval as a Duration; None when it is negative.

Source

pub fn parse(s: &str) -> Result<TimeSpan, FormatError>

Parses an interval in the invariant format [-]{ d | [d.]hh:mm[:ss[.fffffff]] | d:hh:mm:ss[.fffffff] }.

Source§

impl TimeSpan

Members used by the date and time types and the pickers.

Source

pub fn from_hms(hours: i32, minutes: i32, seconds: i32) -> Self

The interval of the given hours, minutes and seconds (the C# constructor TimeSpan(int, int, int)). Panics on overflow.

Source

pub fn from_dhms(days: i32, hours: i32, minutes: i32, seconds: i32) -> Self

The interval of the given days, hours, minutes and seconds (the C# constructor TimeSpan(int, int, int, int)). Panics on overflow.

Source

pub fn from_dhms_milliseconds( days: i32, hours: i32, minutes: i32, seconds: i32, milliseconds: i32, ) -> Self

The interval of the given days, hours, minutes, seconds and milliseconds (the C# constructor TimeSpan(int, int, int, int, int)). Panics on overflow.

Source

pub fn from_hours(value: f64) -> Self

Creates an interval from a number of hours.

Source

pub fn from_days(value: f64) -> Self

Creates an interval from a number of days.

Source

pub const fn days(self) -> i32

The whole days of the interval (negative for a negative interval).

Source

pub const fn hours(self) -> i32

The hours component, -23..=23.

Source

pub const fn minutes(self) -> i32

The minutes component, -59..=59.

Source

pub const fn seconds(self) -> i32

The seconds component, -59..=59.

Source

pub const fn milliseconds(self) -> i32

The milliseconds component, -999..=999.

Source

pub fn total_days(self) -> f64

The interval in whole and fractional days.

Source

pub fn total_hours(self) -> f64

The interval in whole and fractional hours.

Source

pub fn total_minutes(self) -> f64

The interval in whole and fractional minutes.

Source

pub fn duration(self) -> TimeSpan

The absolute value of the interval. Panics for TimeSpan::MIN_VALUE.

Source

pub fn to_string_format(self, format: &str) -> String

Formats with a standard (c, t, T, g, G) or custom .NET TimeSpan format string; an empty format is c. Panics when the format string is invalid (.NET throws FormatException).

The g and G formats always use . as the decimal separator; .NET uses the one of the culture.

Source

pub fn try_to_string_format(self, format: &str) -> Result<String, FormatError>

Like to_string_format, but gives the error of an invalid format string.

Trait Implementations§

Source§

impl Add for TimeSpan

Source§

type Output = TimeSpan

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add<TimeSpan> for DateTime

Source§

type Output = DateTime

The resulting type after applying the + operator.
Source§

fn add(self, rhs: TimeSpan) -> DateTime

Performs the + operation. Read more
Source§

impl Add<TimeSpan> for DateTimeOffset

Source§

type Output = DateTimeOffset

The resulting type after applying the + operator.
Source§

fn add(self, rhs: TimeSpan) -> DateTimeOffset

Performs the + operation. Read more
Source§

impl AddAssign for TimeSpan

Source§

fn add_assign(&mut self, rhs: TimeSpan)

Performs the += operation. Read more
Source§

impl AddAssign<TimeSpan> for DateTime

Source§

fn add_assign(&mut self, rhs: TimeSpan)

Performs the += operation. Read more
Source§

impl AddAssign<TimeSpan> for DateTimeOffset

Source§

fn add_assign(&mut self, rhs: TimeSpan)

Performs the += operation. Read more
Source§

impl Clone for TimeSpan

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for TimeSpan

Source§

impl Debug for TimeSpan

Source§

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

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

impl Default for TimeSpan

Source§

fn default() -> Self

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

impl Display for TimeSpan

Source§

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

Formats as [-][d.]hh:mm:ss[.fffffff].

Source§

impl Eq for TimeSpan

Source§

impl From<Duration> for TimeSpan

Source§

fn from(value: Duration) -> Self

Converts a duration, truncating to whole ticks and saturating at TimeSpan::MAX_VALUE.

Source§

impl FromStr for TimeSpan

Source§

type Err = FormatError

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 TimeSpan

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 IObservable<TimeSpan> for Clock

Source§

fn subscribe( &self, observer: Rc<dyn IObserver<TimeSpan>>, ) -> Rc<dyn IDisposable>

Subscribes observer; disposing the returned handle unsubscribes it.
Source§

impl IObservable<TimeSpan> for MediaContextClock

Source§

fn subscribe( &self, observer: Rc<dyn IObserver<TimeSpan>>, ) -> Rc<dyn IDisposable>

Subscribes observer; disposing the returned handle unsubscribes it.
Source§

impl MarkupTyped for TimeSpan

Source§

const MARKUP: &'static MarkupType

The markup metadata of the type.
Source§

impl Mul<f64> for TimeSpan

Source§

fn mul(self, rhs: f64) -> TimeSpan

Scales the interval, rounding to the nearest tick.

Source§

type Output = TimeSpan

The resulting type after applying the * operator.
Source§

impl Neg for TimeSpan

Source§

type Output = TimeSpan

The resulting type after applying the - operator.
Source§

fn neg(self) -> TimeSpan

Performs the unary - operation. Read more
Source§

impl Ord for TimeSpan

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

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

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

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for TimeSpan

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for TimeSpan

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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 StructuralPartialEq for TimeSpan

Source§

impl Sub for TimeSpan

Source§

type Output = TimeSpan

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub<TimeSpan> for DateTime

Source§

type Output = DateTime

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: TimeSpan) -> DateTime

Performs the - operation. Read more
Source§

impl Sub<TimeSpan> for DateTimeOffset

Source§

type Output = DateTimeOffset

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: TimeSpan) -> DateTimeOffset

Performs the - operation. Read more
Source§

impl SubAssign for TimeSpan

Source§

fn sub_assign(&mut self, rhs: TimeSpan)

Performs the -= operation. Read more
Source§

impl SubAssign<TimeSpan> for DateTime

Source§

fn sub_assign(&mut self, rhs: TimeSpan)

Performs the -= operation. Read more
Source§

impl SubAssign<TimeSpan> for DateTimeOffset

Source§

fn sub_assign(&mut self, rhs: TimeSpan)

Performs the -= operation. Read more

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> AnyValue for T
where T: PartialEq + 'static,

Source§

fn any_value_as_any(&self) -> &(dyn Any + 'static)

Source§

fn any_value_eq(&self, other: &(dyn AnyValue + 'static)) -> bool

Source§

fn any_value_type_name(&self) -> &'static str

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> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). 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> PropertyValue for T
where T: Clone + PartialEq + 'static,

Source§

impl<T> ResourceKeyObject for T
where T: Eq + Hash + 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn dyn_eq(&self, other: &(dyn ResourceKeyObject + 'static)) -> bool

Source§

fn dyn_hash(&self, state: &mut dyn Hasher)

Source§

fn key_type_name(&self) -> &'static str

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.