Skip to content
Merged
Changes from 2 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
36 changes: 31 additions & 5 deletions src/builtins/core/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

use super::{
duration::normalized::{NormalizedDurationRecord, NormalizedTimeDuration},
Duration, PartialDate, PartialTime, PlainDate, PlainTime,
Duration, PartialDate, PartialTime, PlainDate, PlainTime, ZonedDateTime,
};
use crate::{
builtins::core::{calendar::Calendar, Instant},
iso::{IsoDate, IsoDateTime, IsoTime},
options::{
ArithmeticOverflow, DifferenceOperation, DifferenceSettings, DisplayCalendar,
ResolvedRoundingOptions, RoundingOptions, TemporalUnit, ToStringRoundingOptions, UnitGroup,
ArithmeticOverflow, DifferenceOperation, DifferenceSettings, Disambiguation,
DisplayCalendar, ResolvedRoundingOptions, RoundingOptions, TemporalUnit,
ToStringRoundingOptions, UnitGroup,
},
parsers::{parse_date_time, IxdtfStringBuilder},
primitive::FiniteF64,
provider::NeverProvider,
provider::{NeverProvider, TimeZoneProvider},
temporal_assert, MonthCode, TemporalError, TemporalResult, TemporalUnwrap, TimeZone,
};
use alloc::string::String;
Expand Down Expand Up @@ -682,8 +683,33 @@ impl PlainDateTime {
Ok(Self::new_unchecked(result, self.calendar.clone()))
}

pub fn to_zoned_date_time_with_provider(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add a PlainDateTime::to_zoned_date_time implementation on PlainDateTime in compiled.

It looks like I missed adding this stub. So a new module should be added to the compiled directory for PlainDateTime and the companion method added.

Worthwhile note: there's no current need to add this method to temporal_capi just yet because time zone providers over the FFI is still a work in progress. So only the non provider method implementation is needed.

&self,
time_zone: &TimeZone,
disambiguation: Disambiguation,
provider: &impl TimeZoneProvider,
) -> TemporalResult<ZonedDateTime> {
// 6. Let epochNs be ? GetEpochNanosecondsFor(timeZone, dateTime.[[ISODateTime]], disambiguation).
let epoch_ns = time_zone.get_epoch_nanoseconds_for(self.iso, disambiguation, provider)?;
// 7. Return ! CreateTemporalZonedDateTime(epochNs, timeZone, dateTime.[[Calendar]]).
Ok(ZonedDateTime::new_unchecked(
Instant::from(epoch_ns),
self.calendar.clone(),
time_zone.clone(),
))
}

pub fn to_plain_date(&self) -> TemporalResult<PlainDate> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add a temporal_capi implementation of to_plain_date for the FFI

This one may be a little harder because it's dealing with the diplomat bindings, but maybe you can take a crack at it. Changes should be made here.

// 3. Return ! CreateTemporalDate(dateTime.[[ISODateTime]].[[ISODate]], dateTime.[[Calendar]]).
Ok(PlainDate::new_unchecked(
self.iso.date,
self.calendar.clone(),
))
}

pub fn to_plain_time(&self) -> TemporalResult<PlainTime> {
Err(TemporalError::general("Not yet implemented."))
// 3. Return ! CreateTemporalTime(dateTime.[[ISODateTime]].[[Time]]).
Ok(PlainTime::new_unchecked(self.iso.time))
}

pub fn to_ixdtf_string(
Expand Down