pub struct TimeDuration { /* private fields */ }Expand description
A span or delta in time, measured in microseconds.
Analogous to std::time::Duration, and to C#’s TimeSpan.
Name chosen to avoid ambiguity with either of those types.
Unlike Duration, but like C#’s TimeSpan,
TimeDuration can represent negative values.
It also offers less range than Duration, so conversions in both directions may fail.
Implementations§
Source§impl TimeDuration
impl TimeDuration
pub const ZERO: TimeDuration
Sourcepub fn from_micros(micros: i64) -> TimeDuration
pub fn from_micros(micros: i64) -> TimeDuration
Construct a TimeDuration which is micros microseconds.
Sourcepub fn to_duration(self) -> Result<Duration, Duration>
pub fn to_duration(self) -> Result<Duration, Duration>
Returns Err(abs(self) as Duration) if self is negative.
Sourcepub fn to_duration_abs(self) -> Duration
pub fn to_duration_abs(self) -> Duration
Returns a Duration representing the absolute magnitude of self.
Regardless of whether self is positive or negative, the returned Duration is positive.
Sourcepub fn abs(self) -> TimeDuration
pub fn abs(self) -> TimeDuration
Returns a positive TimeDuration with the magnitude of self.
Sourcepub fn from_duration(duration: Duration) -> TimeDuration
pub fn from_duration(duration: Duration) -> TimeDuration
Return a TimeDuration which represents the same span as duration.
Panics if duration.as_micros overflows an i64
Sourcepub fn checked_add(self, other: TimeDuration) -> Option<TimeDuration>
pub fn checked_add(self, other: TimeDuration) -> Option<TimeDuration>
Returns Some(self + other), or None if that value would be out of bounds for TimeDuration.
Sourcepub fn checked_sub(self, other: TimeDuration) -> Option<TimeDuration>
pub fn checked_sub(self, other: TimeDuration) -> Option<TimeDuration>
Returns Some(self - other), or None if that value would be out of bounds for TimeDuration.
Sourcepub fn to_iso8601(self) -> String
pub fn to_iso8601(self) -> String
Generate an iso8601 format string.
This is the better supported format for use for the pg wire protocol.
Example:
use std::time::Duration;
use spacetimedb_sats::time_duration::TimeDuration;
assert_eq!( TimeDuration::from_micros(0).to_iso8601().as_str(), "P0D");
assert_eq!( TimeDuration::from_micros(-1_000_000).to_iso8601().as_str(), "-PT1S");
assert_eq!( TimeDuration::from_duration(Duration::from_secs(60 * 24)).to_iso8601().as_str(), "PT1440S");Trait Implementations§
Source§impl Add<TimeDuration> for Timestamp
impl Add<TimeDuration> for Timestamp
Source§impl Add for TimeDuration
impl Add for TimeDuration
Source§type Output = TimeDuration
type Output = TimeDuration
+ operator.Source§fn add(self, rhs: TimeDuration) -> <TimeDuration as Add>::Output
fn add(self, rhs: TimeDuration) -> <TimeDuration as Add>::Output
+ operation. Read moreSource§impl AddAssign<TimeDuration> for Timestamp
impl AddAssign<TimeDuration> for Timestamp
Source§fn add_assign(&mut self, other: TimeDuration)
fn add_assign(&mut self, other: TimeDuration)
+= operation. Read moreSource§impl AddAssign for TimeDuration
impl AddAssign for TimeDuration
Source§fn add_assign(&mut self, rhs: TimeDuration)
fn add_assign(&mut self, rhs: TimeDuration)
+= operation. Read moreSource§impl Clone for TimeDuration
impl Clone for TimeDuration
Source§fn clone(&self) -> TimeDuration
fn clone(&self) -> TimeDuration
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TimeDuration
impl Debug for TimeDuration
Source§impl<'de> Deserialize<'de> for TimeDuration
impl<'de> Deserialize<'de> for TimeDuration
Source§fn deserialize<D>(
deserializer: D,
) -> Result<TimeDuration, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<TimeDuration, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
deserializer.Source§impl Display for TimeDuration
impl Display for TimeDuration
Source§impl From<Duration> for TimeDuration
impl From<Duration> for TimeDuration
Source§fn from(d: Duration) -> TimeDuration
fn from(d: Duration) -> TimeDuration
Source§impl From<TimeDuration> for AlgebraicValue
impl From<TimeDuration> for AlgebraicValue
Source§fn from(value: TimeDuration) -> AlgebraicValue
fn from(value: TimeDuration) -> AlgebraicValue
Source§impl From<TimeDuration> for ScheduleAt
impl From<TimeDuration> for ScheduleAt
Source§fn from(value: TimeDuration) -> Self
fn from(value: TimeDuration) -> Self
Source§impl GroundSpacetimeType for TimeDuration
impl GroundSpacetimeType for TimeDuration
Source§fn get_type() -> AlgebraicType
fn get_type() -> AlgebraicType
AlgebraicType representation of Self.Source§impl Hash for TimeDuration
impl Hash for TimeDuration
Source§impl Ord for TimeDuration
impl Ord for TimeDuration
Source§fn cmp(&self, other: &TimeDuration) -> Ordering
fn cmp(&self, other: &TimeDuration) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for TimeDuration
impl PartialEq for TimeDuration
Source§impl PartialOrd for TimeDuration
impl PartialOrd for TimeDuration
Source§impl Serialize for TimeDuration
impl Serialize for TimeDuration
Source§fn serialize<S>(
&self,
__serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
__serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
self in the data format of S using the provided serializer.Source§impl SpacetimeType for TimeDuration
impl SpacetimeType for TimeDuration
Source§fn make_type<S>(_ts: &mut S) -> AlgebraicTypewhere
S: TypespaceBuilder,
fn make_type<S>(_ts: &mut S) -> AlgebraicTypewhere
S: TypespaceBuilder,
AlgebraicType representing the type for Self in SATS
and in the typing context in typespace. This is used by the
automatic type registration system in Rust modules. Read moreSource§impl Sub<TimeDuration> for Timestamp
impl Sub<TimeDuration> for Timestamp
Source§impl Sub for TimeDuration
impl Sub for TimeDuration
Source§type Output = TimeDuration
type Output = TimeDuration
- operator.Source§fn sub(self, rhs: TimeDuration) -> <TimeDuration as Sub>::Output
fn sub(self, rhs: TimeDuration) -> <TimeDuration as Sub>::Output
- operation. Read moreSource§impl SubAssign<TimeDuration> for Timestamp
impl SubAssign<TimeDuration> for Timestamp
Source§fn sub_assign(&mut self, rhs: TimeDuration)
fn sub_assign(&mut self, rhs: TimeDuration)
-= operation. Read moreSource§impl SubAssign for TimeDuration
impl SubAssign for TimeDuration
Source§fn sub_assign(&mut self, rhs: TimeDuration)
fn sub_assign(&mut self, rhs: TimeDuration)
-= operation. Read moreimpl Copy for TimeDuration
impl Eq for TimeDuration
impl StructuralPartialEq for TimeDuration
Auto Trait Implementations§
impl Freeze for TimeDuration
impl RefUnwindSafe for TimeDuration
impl Send for TimeDuration
impl Sync for TimeDuration
impl Unpin for TimeDuration
impl UnwindSafe for TimeDuration
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§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Satn for T
impl<T> Satn for T
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
f.Source§fn fmt_psql(
&self,
f: &mut Formatter<'_>,
ty: &PsqlType<'_>,
) -> Result<(), Error>
fn fmt_psql( &self, f: &mut Formatter<'_>, ty: &PsqlType<'_>, ) -> Result<(), Error>
f.Source§fn to_satn(&self) -> String
fn to_satn(&self) -> String
String.Source§fn to_satn_pretty(&self) -> String
fn to_satn_pretty(&self) -> String
String.