Timespan

Struct Timespan 

Source
pub struct Timespan(/* private fields */);
Expand description

Represents an elapsed span of time

Implementations§

Source§

impl Timespan

Source

pub fn from_nanos(nanos: i64) -> Self

Creates a Timespan from the specified number of nanoseconds.

Examples found in repository?
examples/working_with_time.rs (line 12)
7fn main() {
8    let t = Timestamp::from(SystemTime::now());
9    println!("{} nanos from unix epoch", t.as_nanos_unix());
10    println!("{} nanos from 1 Jan 2000 (KDB epoch)", t.as_raw());
11
12    let ts = Timespan::from_nanos(60_000_000_000);
13    let ts2 = Timespan::from_secs(60);
14    let ts3 = Timespan::try_from(Duration::from_secs(60)).unwrap();
15    assert_eq!(ts, ts2);
16    assert_eq!(ts, ts3);
17
18    let d = Date::new(2020, 2, 12);
19    assert_eq!(d.as_raw(), 20 * 365 + 5 + 31 + 12 - 1); // Days from 1 Jan 2000
20}
Source

pub fn from_micros(micros: i64) -> Self

Creates a Timespan from the specified number of microseconds.

Source

pub fn from_millis(millis: i64) -> Self

Creates a Timespan from the specified number of milliseconds.

Source

pub fn from_secs(millis: i64) -> Self

Creates a Timespan from the specified number of seconds.

Examples found in repository?
examples/working_with_time.rs (line 13)
7fn main() {
8    let t = Timestamp::from(SystemTime::now());
9    println!("{} nanos from unix epoch", t.as_nanos_unix());
10    println!("{} nanos from 1 Jan 2000 (KDB epoch)", t.as_raw());
11
12    let ts = Timespan::from_nanos(60_000_000_000);
13    let ts2 = Timespan::from_secs(60);
14    let ts3 = Timespan::try_from(Duration::from_secs(60)).unwrap();
15    assert_eq!(ts, ts2);
16    assert_eq!(ts, ts3);
17
18    let d = Date::new(2020, 2, 12);
19    assert_eq!(d.as_raw(), 20 * 365 + 5 + 31 + 12 - 1); // Days from 1 Jan 2000
20}

Trait Implementations§

Source§

impl Clone for Timespan

Source§

fn clone(&self) -> Timespan

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Timespan

Source§

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

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

impl From<Atom<Timespan>> for Timespan

Source§

fn from(val: Atom<Timespan>) -> Timespan

Converts to this type from the input type.
Source§

impl From<Timespan> for Duration

Source§

fn from(span: Timespan) -> Duration

Converts to this type from the input type.
Source§

impl From<Timespan> for i64

Source§

fn from(val: Timespan) -> i64

Converts to this type from the input type.
Source§

impl From<i64> for Timespan

Source§

fn from(val: i64) -> Timespan

Converts to this type from the input type.
Source§

impl PartialEq for Timespan

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<Duration> for Timespan

Source§

type Error = ConversionError

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

fn try_from(d: Duration) -> Result<Timespan, Self::Error>

Performs the conversion.
Source§

impl Copy for Timespan

Source§

impl Eq for Timespan

Source§

impl StructuralPartialEq for Timespan

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> 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> 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.