From 74162b19f3cadba60734007470d21a727b6a938c Mon Sep 17 00:00:00 2001 From: Able Date: Mon, 5 Dec 2022 01:24:00 -0600 Subject: [PATCH] add in a time library --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + libraries/time/Cargo.toml | 9 +++++++++ libraries/time/src/lib.rs | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 libraries/time/Cargo.toml create mode 100644 libraries/time/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index db5efd8..de202d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -273,6 +273,13 @@ dependencies = [ "syn", ] +[[package]] +name = "time" +version = "0.1.0" +dependencies = [ + "versioning", +] + [[package]] name = "toml" version = "0.5.9" diff --git a/Cargo.toml b/Cargo.toml index 7ad4d9e..b227d42 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ members = [ "libraries/trash_manifest", "libraries/versioning", "libraries/table", + "libraries/time", "programs/delete", "programs/list", diff --git a/libraries/time/Cargo.toml b/libraries/time/Cargo.toml new file mode 100644 index 0000000..b4466fa --- /dev/null +++ b/libraries/time/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "time" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +versioning = { path = "../versioning" } diff --git a/libraries/time/src/lib.rs b/libraries/time/src/lib.rs new file mode 100644 index 0000000..ef178c0 --- /dev/null +++ b/libraries/time/src/lib.rs @@ -0,0 +1,37 @@ +#![no_std] + +use versioning::Version; +pub const VERSION: Version = Version::new(0, 1, 0); + +pub struct Time { + pub secs: u64, + pub nanos: u32, +} +impl Time { + pub fn now() -> Time { + let secs = 0; + let nanos = 0; + Time { secs, nanos } + } + + pub fn elapsed(&self) -> TimeDuration { + let secs = 0; + let nanos = 0; + TimeDuration { secs, nanos } + } +} + +pub struct TimeDuration { + pub secs: u64, + pub nanos: u32, +} + +impl TimeDuration { + pub fn from_secs(secs: u64) -> TimeDuration { + TimeDuration { secs, nanos: 0 } + } + + pub fn as_secs(&self) -> u64 { + self.secs + } +}