diff --git a/cap-time-ext/Cargo.toml b/cap-time-ext/Cargo.toml index fe75314a..796b9a3f 100644 --- a/cap-time-ext/Cargo.toml +++ b/cap-time-ext/Cargo.toml @@ -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"] } diff --git a/cap-time-ext/src/lib.rs b/cap-time-ext/src/lib.rs index f326142c..99a3de81 100644 --- a/cap-time-ext/src/lib.rs +++ b/cap-time-ext/src/lib.rs @@ -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; diff --git a/cap-time-ext/src/timezone.rs b/cap-time-ext/src/timezone.rs new file mode 100644 index 00000000..4cc440e8 --- /dev/null +++ b/cap-time-ext/src/timezone.rs @@ -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 { + get_timezone().map_err(|e| TimezoneError(e.to_string())) + } +}