-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add time module to API * Remove rej files
- Loading branch information
Showing
4 changed files
with
31 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use crate::sys; | ||
use crate::api::syscall; | ||
|
||
use time::{OffsetDateTime, Duration, UtcOffset}; | ||
|
||
pub fn now() -> OffsetDateTime { | ||
let s = syscall::realtime(); // Since Unix Epoch | ||
let ns = Duration::nanoseconds(libm::floor(1e9 * (s - libm::floor(s))) as i64); | ||
OffsetDateTime::from_unix_timestamp(s as i64).to_offset(offset()) + ns | ||
} | ||
|
||
pub fn from_timestamp(ts: i64) -> OffsetDateTime { | ||
OffsetDateTime::from_unix_timestamp(ts).to_offset(offset()) | ||
} | ||
|
||
fn offset() -> UtcOffset { | ||
if let Some(tz) = sys::process::env("TZ") { | ||
if let Ok(offset) = tz.parse::<i32>() { | ||
return UtcOffset::seconds(offset); | ||
} | ||
} | ||
UtcOffset::seconds(0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters