Timestamp

Struct Timestamp 

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

Represents a timestamp in KDB. Conversions between the Unix Epoch and the KDB Epoch are done automatically.

Implementations§

Source§

impl Timestamp

Source

pub fn from_nanos_unix(n: u64) -> Timestamp

Creates a timestamp from a count of nanoseconds in the unix epoch.

Source

pub fn as_nanos_unix(&self) -> u64

Converts the timestamp to the number of nanoseconds from the unix epoch and returns it.

Examples found in repository?
examples/working_with_time.rs (line 9)
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 as_raw(&self) -> i64

Returns the raw timestamp stored as KDB values.

Examples found in repository?
examples/working_with_time.rs (line 10)
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_raw(nanos_since_millenium: i64) -> Timestamp

Creates a timestamp based on a count of nanoseconds since 1 Jan 2000.

Trait Implementations§

Source§

impl Clone for Timestamp

Source§

fn clone(&self) -> Timestamp

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 Timestamp

Source§

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

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

impl From<Atom<Timestamp>> for Timestamp

Source§

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

Converts to this type from the input type.
Source§

impl From<SystemTime> for Timestamp

Source§

fn from(st: SystemTime) -> Timestamp

Converts to this type from the input type.
Source§

impl From<Timestamp> for SystemTime

Source§

fn from(date: Timestamp) -> SystemTime

Converts to this type from the input type.
Source§

impl From<Timestamp> for i64

Source§

fn from(val: Timestamp) -> i64

Converts to this type from the input type.
Source§

impl From<i64> for Timestamp

Source§

fn from(val: i64) -> Timestamp

Converts to this type from the input type.
Source§

impl PartialEq for Timestamp

Source§

fn eq(&self, other: &Timestamp) -> 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 Copy for Timestamp

Source§

impl Eq for Timestamp

Source§

impl StructuralPartialEq for Timestamp

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.