Skip to content

Commit 869ac65

Browse files
committed
Add timezone.
1 parent 963eebf commit 869ac65

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

cap-primitives/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ maybe-owned = "0.3.4"
2020
fs-set-times = "0.20.0"
2121
io-extras = "0.18.0"
2222
io-lifetimes = { version = "2.0.0", default-features = false }
23+
iana-time-zone = "0.1.57"
2324

2425
[dev-dependencies]
2526
cap-tempfile = { path = "../cap-tempfile" }

cap-primitives/src/time/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ mod instant;
44
mod monotonic_clock;
55
mod system_clock;
66
mod system_time;
7+
mod timezone;
78

89
pub use instant::Instant;
910
pub use monotonic_clock::MonotonicClock;
1011
pub use system_clock::SystemClock;
1112
pub use system_time::SystemTime;
13+
pub use timezone::Timezone;
1214

1315
pub use std::time::{Duration, SystemTimeError};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use ambient_authority::AmbientAuthority;
2+
use iana_time_zone::get_timezone;
3+
4+
/// A reference to a timezone resource.
5+
pub struct Timezone(());
6+
7+
#[derive(Debug)]
8+
pub struct TimezoneError(String);
9+
10+
//impl LocalResult for TimezoneError {
11+
impl Timezone {
12+
/// Constructs a new instance of `Self`.
13+
///
14+
/// # Ambient Authority
15+
///
16+
/// This uses ambient authority to accesses clocks.
17+
#[inline]
18+
pub const fn new(ambient_authority: AmbientAuthority) -> Self {
19+
let _ = ambient_authority;
20+
Self(())
21+
}
22+
23+
/// Returns the combined date and time with timezone.
24+
///
25+
/// Converts NaiveTime to DateTime
26+
#[inline]
27+
pub fn timezone_name(&self) -> Result<String, TimezoneError> {
28+
get_timezone().map_err(|e| TimezoneError(e.to_string()))
29+
}
30+
}

0 commit comments

Comments
 (0)