Skip to content

Commit

Permalink
feat: (time) add epoch_nanos()
Browse files Browse the repository at this point in the history
  • Loading branch information
madelynwith5ns committed May 9, 2024
1 parent 5a9fe78 commit 8ca4ce3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ fn time_interface() {
second(now);
timestamp(now);
timestamp_now();
epoch_nanos();
}
9 changes: 9 additions & 0 deletions src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ pub fn epoch_millis() -> u128 {
};
}

/// Same as epoch_millis() but in nanoseconds.
pub fn epoch_nanos() -> u128 {
let now = std::time::SystemTime::now();
return match now.duration_since(std::time::UNIX_EPOCH) {
Ok(duration) => duration.as_nanos(),
Err(_) => 0,
};
}

/// Returns the number of days since the UNIX epoch.
pub fn epoch_days(point: u128) -> u128 {
// you all know what that 86.4m is
Expand Down

0 comments on commit 8ca4ce3

Please sign in to comment.