pub struct TimeInterval { /* private fields */ }
Expand description
An interval or duration of time between two DateTime
s.
The easiest way to create a TimeInterval
is often with the time_interval
macro, which
uses a domain-specific language:
§Examples
use datetime::interval::TimeInterval;
use datetime::time_interval;
assert_eq!(time_interval!(5m 30s), TimeInterval::new(330, 0));
assert_eq!(time_interval!(-1h 30m), TimeInterval::new(-5_400, 0));
assert_eq!(time_interval!(10.5s), TimeInterval::new(10, 500_000_000));
Implementations§
Source§impl TimeInterval
impl TimeInterval
Sourcepub const fn new(seconds: i64, nanos: u32) -> Self
pub const fn new(seconds: i64, nanos: u32) -> Self
Create a new TimeInterval
from seconds and nanoseconds.
Sourcepub const fn from_milliseconds(millis: i64) -> Self
pub const fn from_milliseconds(millis: i64) -> Self
Create a new TimeInterval
from a value in milliseconds.
Sourcepub const fn from_microseconds(micros: i64) -> Self
pub const fn from_microseconds(micros: i64) -> Self
Create a new TimeInterval
from a value in microseconds.
Sourcepub const fn from_nanoseconds(nanos: i128) -> Self
pub const fn from_nanoseconds(nanos: i128) -> Self
Create a new TimeInterval
from a value in nanoseconds.
Sourcepub const fn seconds(&self) -> i64
pub const fn seconds(&self) -> i64
The number of seconds this interval represents.
Note that the nanoseconds value is always positive, even if seconds is negative. For example, an interval representing -2.5 seconds will be represented as -3 seconds and 500,000,000 nanos.
Sourcepub const fn nanoseconds(&self) -> u32
pub const fn nanoseconds(&self) -> u32
The number of nanoseconds this interval represents.
Note that the nanoseconds value is always positive, even if seconds is negative. For example, an interval representing -2.5 seconds will be represented as -3 seconds and 500,000,000 nanos.
Sourcepub const fn as_milliseconds(&self) -> i64
pub const fn as_milliseconds(&self) -> i64
The number of milliseconds this interval represents.
Sourcepub const fn as_microseconds(&self) -> i64
pub const fn as_microseconds(&self) -> i64
The number of microseconds this interval represents.
Sourcepub const fn as_nanoseconds(&self) -> i128
pub const fn as_nanoseconds(&self) -> i128
The number of nanoseconds this interval represents.
Trait Implementations§
Source§impl Add<TimeInterval> for DateTime
impl Add<TimeInterval> for DateTime
Source§impl AddAssign<TimeInterval> for DateTime
impl AddAssign<TimeInterval> for DateTime
Source§fn add_assign(&mut self, rhs: TimeInterval)
fn add_assign(&mut self, rhs: TimeInterval)
+=
operation. Read moreSource§impl Clone for TimeInterval
impl Clone for TimeInterval
Source§fn clone(&self) -> TimeInterval
fn clone(&self) -> TimeInterval
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for TimeInterval
impl Debug for TimeInterval
Source§impl Default for TimeInterval
impl Default for TimeInterval
Source§fn default() -> TimeInterval
fn default() -> TimeInterval
Source§impl Div for TimeInterval
impl Div for TimeInterval
Source§impl Ord for TimeInterval
impl Ord for TimeInterval
Source§fn cmp(&self, other: &TimeInterval) -> Ordering
fn cmp(&self, other: &TimeInterval) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl Parse for TimeInterval
Available on crate feature syn
only.
impl Parse for TimeInterval
syn
only.fn parse(input: ParseStream<'_>) -> Result<Self>
Source§impl PartialEq for TimeInterval
impl PartialEq for TimeInterval
Source§impl PartialOrd for TimeInterval
impl PartialOrd for TimeInterval
Source§impl Sub<TimeInterval> for DateTime
impl Sub<TimeInterval> for DateTime
Source§impl SubAssign<TimeInterval> for DateTime
impl SubAssign<TimeInterval> for DateTime
Source§fn sub_assign(&mut self, rhs: TimeInterval)
fn sub_assign(&mut self, rhs: TimeInterval)
-=
operation. Read moreimpl Copy for TimeInterval
impl Eq for TimeInterval
impl StructuralPartialEq for TimeInterval
Auto Trait Implementations§
impl Freeze for TimeInterval
impl RefUnwindSafe for TimeInterval
impl Send for TimeInterval
impl Sync for TimeInterval
impl Unpin for TimeInterval
impl UnwindSafe for TimeInterval
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self
to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self
to an expression for Diesel’s query builder. Read more