add in a time library

This commit is contained in:
Able 2022-12-05 01:24:00 -06:00
parent 919e0312cb
commit 74162b19f3
4 changed files with 54 additions and 0 deletions

7
Cargo.lock generated
View file

@ -273,6 +273,13 @@ dependencies = [
"syn",
]
[[package]]
name = "time"
version = "0.1.0"
dependencies = [
"versioning",
]
[[package]]
name = "toml"
version = "0.5.9"

View file

@ -14,6 +14,7 @@ members = [
"libraries/trash_manifest",
"libraries/versioning",
"libraries/table",
"libraries/time",
"programs/delete",
"programs/list",

View file

@ -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" }

37
libraries/time/src/lib.rs Normal file
View file

@ -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
}
}