Skip to content

Commit 2607c07

Browse files
authored
Add from_nanoseconds to FFI PlainDateTime (#583)
Closes #579.
1 parent 8e509ac commit 2607c07

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

temporal_capi/bindings/c/PlainDateTime.h

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

temporal_capi/bindings/cpp/temporal_rs/PlainDateTime.d.hpp

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

temporal_capi/bindings/cpp/temporal_rs/PlainDateTime.hpp

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

temporal_capi/src/plain_date_time.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod ffi {
66
use crate::calendar::ffi::{AnyCalendarKind, Calendar};
77
use crate::duration::ffi::Duration;
88
use crate::error::ffi::TemporalError;
9+
use crate::instant::ffi::I128Nanoseconds;
910
use crate::options::ffi::{
1011
ArithmeticOverflow, DifferenceSettings, DisplayCalendar, RoundingOptions,
1112
ToStringRoundingOptions,
@@ -135,6 +136,22 @@ pub mod ffi {
135136
let zdt = crate::zoned_date_time::zdt_from_epoch_ms_with_provider(ms, tz.into(), p)?;
136137
Ok(Box::new(Self(zdt.to_plain_date_time())))
137138
}
139+
#[cfg(feature = "compiled_data")]
140+
pub fn from_epoch_nanoseconds<'p>(
141+
ns: I128Nanoseconds,
142+
tz: TimeZone,
143+
p: &Provider<'p>,
144+
) -> Result<Box<Self>, TemporalError> {
145+
Self::from_epoch_nanoseconds_with_provider(ns, tz, &Provider::compiled())
146+
}
147+
pub fn from_epoch_nanoseconds_with_provider<'p>(
148+
ns: I128Nanoseconds,
149+
tz: TimeZone,
150+
p: &Provider<'p>,
151+
) -> Result<Box<Self>, TemporalError> {
152+
let zdt = crate::zoned_date_time::zdt_from_epoch_ns_with_provider(ns, tz.into(), p)?;
153+
Ok(Box::new(Self(zdt.to_plain_date_time())))
154+
}
138155
pub fn with(
139156
&self,
140157
partial: PartialDateTime,

temporal_capi/src/zoned_date_time.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::error::ffi::TemporalError;
2+
use crate::instant::ffi::I128Nanoseconds;
23
use crate::provider::ffi::Provider;
34
use temporal_rs::options::RelativeTo;
45

@@ -721,6 +722,17 @@ pub(crate) fn zdt_from_epoch_ms_with_provider<'p>(
721722
.map_err(Into::into)
722723
}
723724

725+
pub(crate) fn zdt_from_epoch_ns_with_provider<'p>(
726+
ns: I128Nanoseconds,
727+
time_zone: temporal_rs::TimeZone,
728+
p: &Provider<'p>,
729+
) -> Result<temporal_rs::ZonedDateTime, TemporalError> {
730+
let instant = temporal_rs::Instant::try_new(ns.into())?;
731+
with_provider!(p, |p| instant
732+
.to_zoned_date_time_iso_with_provider(time_zone, p))
733+
.map_err(Into::into)
734+
}
735+
724736
impl TryFrom<ffi::PartialZonedDateTime<'_>> for temporal_rs::partial::PartialZonedDateTime {
725737
type Error = TemporalError;
726738
fn try_from(other: ffi::PartialZonedDateTime<'_>) -> Result<Self, TemporalError> {

0 commit comments

Comments
 (0)