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
impl Timestamp
Sourcepub fn from_nanos_unix(n: u64) -> Timestamp
pub fn from_nanos_unix(n: u64) -> Timestamp
Creates a timestamp from a count of nanoseconds in the unix epoch.
Sourcepub fn as_nanos_unix(&self) -> u64
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}Sourcepub fn as_raw(&self) -> i64
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}Trait Implementations§
Source§impl From<SystemTime> for Timestamp
impl From<SystemTime> for Timestamp
Source§fn from(st: SystemTime) -> Timestamp
fn from(st: SystemTime) -> Timestamp
Converts to this type from the input type.
Source§impl From<Timestamp> for SystemTime
impl From<Timestamp> for SystemTime
Source§fn from(date: Timestamp) -> SystemTime
fn from(date: Timestamp) -> SystemTime
Converts to this type from the input type.
impl Copy for Timestamp
impl Eq for Timestamp
impl StructuralPartialEq for Timestamp
Auto Trait Implementations§
impl Freeze for Timestamp
impl RefUnwindSafe for Timestamp
impl Send for Timestamp
impl Sync for Timestamp
impl Unpin for Timestamp
impl UnwindSafe for Timestamp
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
Mutably borrows from an owned value. Read more