pub struct Date(/* private fields */);Expand description
Represents the number of days since 1 Jan 2000.
Implementations§
Source§impl Date
impl Date
Sourcepub fn new(year: i32, month: i32, day: i32) -> Self
pub fn new(year: i32, month: i32, day: i32) -> Self
Creates a new date.
Examples found in repository?
examples/working_with_time.rs (line 18)
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) -> i32
pub fn as_raw(&self) -> i32
Returns the date as the number of days since 1 Jan 2000.
Examples found in repository?
examples/working_with_time.rs (line 19)
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<Date> for SystemTime
impl From<Date> for SystemTime
Source§fn from(date: Date) -> SystemTime
fn from(date: Date) -> SystemTime
Converts to this type from the input type.
Source§impl From<SystemTime> for Date
impl From<SystemTime> for Date
Source§fn from(st: SystemTime) -> Date
fn from(st: SystemTime) -> Date
Converts to this type from the input type.
impl Copy for Date
impl Eq for Date
impl StructuralPartialEq for Date
Auto Trait Implementations§
impl Freeze for Date
impl RefUnwindSafe for Date
impl Send for Date
impl Sync for Date
impl Unpin for Date
impl UnwindSafe for Date
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