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
34 changes: 34 additions & 0 deletions src/builtins/compiled/zoneddatetime.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::builtins::TZ_PROVIDER;
use crate::partial::PartialZonedDateTime;
use crate::provider::TransitionDirection;
use crate::ZonedDateTime;
use crate::{
Expand Down Expand Up @@ -222,6 +223,39 @@ impl ZonedDateTime {
/// The following [`ZonedDateTime`] methods are feature gated behind the
/// `compiled_data` feature flag.
impl ZonedDateTime {
#[inline]
pub fn from_partial(
partial: PartialZonedDateTime,
overflow: Option<ArithmeticOverflow>,
disambiguation: Option<Disambiguation>,
offset_option: Option<OffsetDisambiguation>,
) -> TemporalResult<Self> {
Self::from_partial_with_provider(
partial,
overflow,
disambiguation,
offset_option,
&*crate::builtins::TZ_PROVIDER,
)
}

#[inline]
pub fn with(
&self,
partial: PartialZonedDateTime,
disambiguation: Option<Disambiguation>,
offset_option: Option<OffsetDisambiguation>,
overflow: Option<ArithmeticOverflow>,
) -> TemporalResult<Self> {
self.with_with_provider(
partial,
disambiguation,
offset_option,
overflow,
&*TZ_PROVIDER,
)
}

/// Creates a new `ZonedDateTime` from the current `ZonedDateTime` with the provided `PlainTime`.
///
/// combined with the provided `TimeZone`.
Expand Down
12 changes: 12 additions & 0 deletions src/builtins/core/timezone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ impl TimeZone {
TimeZone::UtcOffset(offset) => offset.to_string(),
}
}

/// <https://tc39.es/proposal-temporal/#sec-getavailablenamedtimezoneidentifier> but just a getter
pub fn is_valid_with_provider(&self, provider: &impl TimeZoneProvider) -> bool {

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.

question: This may change in the future depending on changes to TimeZoneProvider and the trait implementations. Is this volatility going to be fine?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Personally I don't care about volatility in temporal_rs; the primary client is boa and as long as that volatility is fine with you it's fine with me.

temporal_capi is where I worry.

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.

I'm fine with volatility for now due to it being flagged experimental in Boa. I think this method could work for now, but I really don't expect it to last for long once the providers start to take shape and the TimeZoneProvider is updated to handle GetAvailableNamedTimeZones better than it currently can.

(Also, as far as temporal_capi, see my other question about compiled_data)

match self {
Self::IanaIdentifier(s) => provider.check_identifier(s),
Self::UtcOffset(..) => true,
}
}
#[cfg(feature = "compiled_data")]
pub fn is_valid(&self) -> bool {
self.is_valid_with_provider(&*crate::builtins::TZ_PROVIDER)
}
}

impl Default for TimeZone {
Expand Down
10 changes: 5 additions & 5 deletions src/builtins/core/zoneddatetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ impl ZonedDateTime {
self.instant
}

pub fn with(
pub fn with_with_provider(
&self,
partial: PartialZonedDateTime,
disambiguation: Option<Disambiguation>,
Expand Down Expand Up @@ -1602,7 +1602,7 @@ mod tests {

let overflow = ArithmeticOverflow::Reject;

let result_1 = zdt.with(
let result_1 = zdt.with_with_provider(
PartialZonedDateTime {
date: PartialDate {
month: Some(29),
Expand All @@ -1618,7 +1618,7 @@ mod tests {
provider,
);

let result_2 = zdt.with(
let result_2 = zdt.with_with_provider(
PartialZonedDateTime {
date: PartialDate {
day: Some(31),
Expand All @@ -1634,7 +1634,7 @@ mod tests {
provider,
);

let result_3 = zdt.with(
let result_3 = zdt.with_with_provider(
PartialZonedDateTime {
date: PartialDate::default(),
time: PartialTime {
Expand All @@ -1650,7 +1650,7 @@ mod tests {
provider,
);

let result_4 = zdt.with(
let result_4 = zdt.with_with_provider(
PartialZonedDateTime {
date: PartialDate::default(),
time: PartialTime {
Expand Down
28 changes: 28 additions & 0 deletions temporal_capi/bindings/c/PartialZonedDateTime.d.h

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

22 changes: 22 additions & 0 deletions temporal_capi/bindings/c/PartialZonedDateTime.h

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

2 changes: 2 additions & 0 deletions temporal_capi/bindings/c/TimeZone.h

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

23 changes: 23 additions & 0 deletions temporal_capi/bindings/c/TransitionDirection.d.h

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

22 changes: 22 additions & 0 deletions temporal_capi/bindings/c/TransitionDirection.h

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

19 changes: 19 additions & 0 deletions temporal_capi/bindings/c/ZonedDateTime.d.h

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

161 changes: 161 additions & 0 deletions temporal_capi/bindings/c/ZonedDateTime.h

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

Loading