Skip to content

Commit 3455746

Browse files
committed
Add TimeZone
1 parent c3c86c7 commit 3455746

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

temporal_capi/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ pub mod plain_date_time;
2929
pub mod plain_month_day;
3030
pub mod plain_time;
3131
pub mod plain_year_month;
32+
33+
pub mod time_zone;

temporal_capi/src/time_zone.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#[diplomat::bridge]
2+
#[diplomat::abi_rename = "temporal_rs_{0}"]
3+
#[diplomat::attr(auto, namespace = "temporal_rs")]
4+
pub mod ffi {
5+
use crate::error::ffi::TemporalError;
6+
use std::str;
7+
8+
#[diplomat::opaque]
9+
pub struct TimeZone(pub temporal_rs::TimeZone);
10+
11+
impl TimeZone {
12+
pub fn try_from_identifier_str(ident: &DiplomatStr) -> Result<Box<Self>, TemporalError> {
13+
let Ok(ident) = str::from_utf8(ident) else {
14+
return Err(temporal_rs::TemporalError::range().into());
15+
};
16+
temporal_rs::TimeZone::try_from_identifier_str(ident)
17+
.map(|x| Box::new(TimeZone(x)))
18+
.map_err(Into::into)
19+
}
20+
pub fn try_from_str(ident: &DiplomatStr) -> Result<Box<Self>, TemporalError> {
21+
let Ok(ident) = str::from_utf8(ident) else {
22+
return Err(temporal_rs::TemporalError::range().into());
23+
};
24+
temporal_rs::TimeZone::try_from_str(ident)
25+
.map(|x| Box::new(TimeZone(x)))
26+
.map_err(Into::into)
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)