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§const fn clone_from(&mut self, source: &Self)
const 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 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 more