Skip to content

Commit

Permalink
Add timezone.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdmurph32 committed Aug 24, 2023
1 parent 963eebf commit a995a8d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions cap-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ maybe-owned = "0.3.4"
fs-set-times = "0.20.0"
io-extras = "0.18.0"
io-lifetimes = { version = "2.0.0", default-features = false }
iana-time-zone = "0.1.57"

[dev-dependencies]
cap-tempfile = { path = "../cap-tempfile" }
Expand Down
2 changes: 2 additions & 0 deletions cap-primitives/src/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ mod instant;
mod monotonic_clock;
mod system_clock;
mod system_time;
mod timezone;

pub use instant::Instant;
pub use monotonic_clock::MonotonicClock;
pub use system_clock::SystemClock;
pub use system_time::SystemTime;
pub use timezone::Timezone;

pub use std::time::{Duration, SystemTimeError};
30 changes: 30 additions & 0 deletions cap-primitives/src/time/timezone.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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 LocalResult for TimezoneError {
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()))
}
}
4 changes: 2 additions & 2 deletions cap-std/src/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
//! This corresponds to [`std::time`].
//!
//! Instead of [`std::time`]'s methods which return the current time, this
//! crate has methods on [`SystemClock`] and [`MonotonicClock`].
//! crate has methods on [`SystemClock`], [`MonotonicClock`] and [`Timezone`].
pub use cap_primitives::time::{
Duration, Instant, MonotonicClock, SystemClock, SystemTime, SystemTimeError,
Duration, Instant, MonotonicClock, SystemClock, SystemTime, SystemTimeError, Timezone,
};

0 comments on commit a995a8d

Please sign in to comment.