Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cap-time-ext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ repository = "https://github.com/bytecodealliance/cap-std"
edition = "2021"

[dependencies]
ambient-authority = "0.0.2"
cap-primitives = { path = "../cap-primitives", version = "^2.0.0" }
cap-std = { path = "../cap-std", optional = true, version = "^2.0.0" }
iana-time-zone = "0.1.57"

[target.'cfg(not(windows))'.dependencies]
rustix = { version = "0.38.0", features = ["time"] }
Expand Down
2 changes: 2 additions & 0 deletions cap-time-ext/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

mod monotonic_clock;
mod system_clock;
mod timezone;

pub use monotonic_clock::MonotonicClockExt;
pub use system_clock::SystemClockExt;
pub use timezone::Timezone;
29 changes: 29 additions & 0 deletions cap-time-ext/src/timezone.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use ambient_authority::AmbientAuthority;
use iana_time_zone::get_timezone;

/// A reference to a timezone resource.
pub struct Timezone(());

#[derive(Debug)]
pub struct TimezoneError(String);

impl Timezone {
/// Constructs a new instance of `Self`.
///
/// # Ambient Authority
///
/// This uses ambient authority to accesses clocks.
#[inline]
pub const fn new(ambient_authority: AmbientAuthority) -> Self {
let _ = ambient_authority;
Self(())
}

/// Returns the combined date and time with timezone.
///
/// Converts NaiveTime to DateTime
#[inline]
pub fn timezone_name(&self) -> Result<String, TimezoneError> {
get_timezone().map_err(|e| TimezoneError(e.to_string()))
}
}