-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup
Now
API in favor of system defined implementations (#182)
~~This adds a `SystemHooks` trait for providing system getters for system time and system time zone. It also adjusts the "now" feature to a "sys" feature flag for `DefaultSystemHooks`.~~ This PR provides more generalized methods that can be used in combination with a system hooks.
- Loading branch information
Showing
6 changed files
with
165 additions
and
85 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
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
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 |
---|---|---|
@@ -1,21 +1,23 @@ | ||
use alloc::string::{String, ToString}; | ||
use alloc::string::String; | ||
|
||
use crate::{TemporalError, TemporalResult}; | ||
use crate::TemporalResult; | ||
|
||
use crate::TemporalError; | ||
use alloc::string::ToString; | ||
use web_time::{SystemTime, UNIX_EPOCH}; | ||
|
||
// TODO: Need to implement SystemTime handling for non_std. | ||
|
||
#[inline] | ||
pub(crate) fn get_system_timezone() -> TemporalResult<String> { | ||
iana_time_zone::get_timezone().map_err(|e| TemporalError::general(e.to_string())) | ||
} | ||
|
||
/// Returns the system time in nanoseconds. | ||
#[cfg(feature = "now")] | ||
#[cfg(feature = "sys")] | ||
pub(crate) fn get_system_nanoseconds() -> TemporalResult<u128> { | ||
SystemTime::now() | ||
.duration_since(UNIX_EPOCH) | ||
.map_err(|e| TemporalError::general(e.to_string())) | ||
.map(|d| d.as_nanos()) | ||
} | ||
|
||
/// Returns the system tz identifier | ||
pub(crate) fn get_system_tz_identifier() -> TemporalResult<String> { | ||
iana_time_zone::get_timezone().map_err(|e| TemporalError::general(e.to_string())) | ||
} |