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
3 changes: 3 additions & 0 deletions temporal_capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ num-traits.workspace = true
temporal_rs = { workspace = true, default-features = false }
icu_calendar = { version = "2.0.0-beta2", default-features = false }

[features]
compiled_data = ["temporal_rs/compiled_data"]

[package.metadata.docs.rs]
all-features = true
5 changes: 5 additions & 0 deletions temporal_capi/bindings/cpp/temporal_rs/Instant.d.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions temporal_capi/bindings/cpp/temporal_rs/Instant.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions temporal_capi/bindings/cpp/temporal_rs/TimeZone.d.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions temporal_capi/bindings/cpp/temporal_rs/TimeZone.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion temporal_capi/src/instant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ pub mod ffi {
use core::str::{self, FromStr};
use diplomat_runtime::{DiplomatStr, DiplomatStr16};

#[cfg(feature = "compiled_data")]
use crate::options::ffi::ToStringRoundingOptions;
#[cfg(feature = "compiled_data")]
use crate::time_zone::ffi::TimeZone;

#[diplomat::opaque]
pub struct Instant(pub temporal_rs::Instant);

Expand Down Expand Up @@ -132,6 +137,22 @@ pub mod ffi {

I128Nanoseconds { high, low }
}
// TODO timezone APIs

#[cfg(feature = "compiled_data")]
pub fn to_ixdtf_string_with_compiled_data(
&self,
zone: Option<&TimeZone>,
options: ToStringRoundingOptions,
write: &mut DiplomatWrite,
) -> Result<(), TemporalError> {
use core::fmt::Write;
let string = self.0.to_ixdtf_string(zone.map(|x| &x.0), options.into())?;
// throw away the error, this should always succeed
let _ = write.write_str(&string);

Ok(())
}

// TODO non-compiled data timezone APIs
}
}
2 changes: 2 additions & 0 deletions temporal_capi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ pub mod plain_date_time;
pub mod plain_month_day;
pub mod plain_time;
pub mod plain_year_month;

pub mod time_zone;
30 changes: 30 additions & 0 deletions temporal_capi/src/time_zone.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#[diplomat::bridge]
#[diplomat::abi_rename = "temporal_rs_{0}"]
#[diplomat::attr(auto, namespace = "temporal_rs")]
pub mod ffi {
use crate::error::ffi::TemporalError;
use alloc::boxed::Box;
use core::str;

#[diplomat::opaque]
pub struct TimeZone(pub temporal_rs::TimeZone);

impl TimeZone {
pub fn try_from_identifier_str(ident: &DiplomatStr) -> Result<Box<Self>, TemporalError> {
let Ok(ident) = str::from_utf8(ident) else {
return Err(temporal_rs::TemporalError::range().into());
};
temporal_rs::TimeZone::try_from_identifier_str(ident)
.map(|x| Box::new(TimeZone(x)))
.map_err(Into::into)
}
pub fn try_from_str(ident: &DiplomatStr) -> Result<Box<Self>, TemporalError> {
let Ok(ident) = str::from_utf8(ident) else {
return Err(temporal_rs::TemporalError::range().into());
};
temporal_rs::TimeZone::try_from_str(ident)
.map(|x| Box::new(TimeZone(x)))
.map_err(Into::into)
}
}
}