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
2 changes: 1 addition & 1 deletion docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ A `TimeZoneProvider` API on a core builtin will look like the below.

```rust
impl ZonedDateTime {
pub fn day_with_provider(&self, provider: &impl TimeZoneProvider) -> TemporalResult<u8> {
pub fn day_with_provider(&self, provider: &(impl TimeZoneProvider + ?Sized)) -> TemporalResult<u8> {
// Code goes here.
}
}
Expand Down
2 changes: 1 addition & 1 deletion provider/src/tzif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1917,7 +1917,7 @@ mod tests {
id: &str,
before_offset: i64,
after_offset: i64,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) {
let id = provider.get(id.as_bytes()).unwrap();
let before_possible = provider
Expand Down
6 changes: 3 additions & 3 deletions src/builtins/core/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ impl Duration {
&self,
other: &Duration,
relative_to: Option<RelativeTo>,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<Ordering> {
if self == other {
return Ok(Ordering::Equal);
Expand Down Expand Up @@ -1054,7 +1054,7 @@ impl Duration {
&self,
options: RoundingOptions,
relative_to: Option<RelativeTo>,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<Self> {
// NOTE(HalidOdat): Steps 1-12 are handled before calling the function.
//
Expand Down Expand Up @@ -1286,7 +1286,7 @@ impl Duration {
&self,
unit: Unit,
relative_to: Option<RelativeTo>,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
// Review question what is the return type of duration.prototye.total?
) -> TemporalResult<FiniteF64> {
match relative_to {
Expand Down
10 changes: 5 additions & 5 deletions src/builtins/core/duration/normalized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ impl InternalDurationRecord {
sign: Sign,
dest_epoch_ns: i128,
dt: &PlainDateTime,
time_zone: Option<(&TimeZone, &impl TimeZoneProvider)>, // ???
time_zone: Option<(&TimeZone, &(impl TimeZoneProvider + ?Sized))>, // ???
options: ResolvedRoundingOptions,
) -> TemporalResult<NudgeRecord> {
// NOTE: r2 may never be used...need to test.
Expand Down Expand Up @@ -660,7 +660,7 @@ impl InternalDurationRecord {
dt: &PlainDateTime,
time_zone: &TimeZone,
options: ResolvedRoundingOptions,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<NudgeRecord> {
let d = self.date();
// 1.Let start be ? CalendarDateAdd(calendar, isoDateTime.[[ISODate]], duration.[[Date]], constrain).
Expand Down Expand Up @@ -822,7 +822,7 @@ impl InternalDurationRecord {
sign: Sign,
nudged_epoch_ns: i128,
iso_date_time: &IsoDateTime,
time_zone: Option<(&TimeZone, &impl TimeZoneProvider)>,
time_zone: Option<(&TimeZone, &(impl TimeZoneProvider + ?Sized))>,
calendar: &Calendar,
largest_unit: Unit,
smallest_unit: Unit,
Expand Down Expand Up @@ -956,7 +956,7 @@ impl InternalDurationRecord {
&self,
dest_epoch_ns: i128,
dt: &PlainDateTime,
time_zone: Option<(&TimeZone, &impl TimeZoneProvider)>,
time_zone: Option<(&TimeZone, &(impl TimeZoneProvider + ?Sized))>,
options: ResolvedRoundingOptions,
) -> TemporalResult<InternalDurationRecord> {
let duration = *self;
Expand Down Expand Up @@ -1014,7 +1014,7 @@ impl InternalDurationRecord {
&self,
dest_epoch_ns: i128,
dt: &PlainDateTime,
time_zone: Option<(&TimeZone, &impl TimeZoneProvider)>,
time_zone: Option<(&TimeZone, &(impl TimeZoneProvider + ?Sized))>,
unit: Unit,
) -> TemporalResult<FiniteF64> {
// 1. If IsCalendarUnit(unit) is true, or timeZone is not unset and unit is day, then
Expand Down
6 changes: 3 additions & 3 deletions src/builtins/core/instant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ impl Instant {
pub fn to_zoned_date_time_iso_with_provider(
&self,
time_zone: TimeZone,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<ZonedDateTime> {
ZonedDateTime::new_unchecked_with_provider(*self, time_zone, Calendar::ISO, provider)
}
Expand All @@ -409,7 +409,7 @@ impl Instant {
&self,
timezone: Option<TimeZone>,
options: ToStringRoundingOptions,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<String> {
self.to_ixdtf_writeable_with_provider(timezone, options, provider)
.map(|x| x.write_to_string().into())
Expand All @@ -420,7 +420,7 @@ impl Instant {
&self,
timezone: Option<TimeZone>,
options: ToStringRoundingOptions,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<impl Writeable + '_> {
let resolved_options = options.resolve()?;
let round = self.round_instant(ResolvedRoundingOptions::from_to_string_options(
Expand Down
17 changes: 10 additions & 7 deletions src/builtins/core/now.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl<H: HostHooks> Now<H> {
pub(crate) fn system_datetime_with_provider(
self,
time_zone: Option<TimeZone>,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<IsoDateTime> {
let system_nanoseconds = self.host_hooks.get_system_epoch_nanoseconds()?;
let time_zone = time_zone.unwrap_or(self.host_hooks.get_system_time_zone(provider)?);
Expand All @@ -34,7 +34,7 @@ impl<H: HostHooks> Now<H> {
/// Converts the current [`Now`] into a [`TimeZone`].
pub fn time_zone_with_provider(
self,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<TimeZone> {
self.host_hooks.get_system_time_zone(provider)
}
Expand All @@ -50,7 +50,7 @@ impl<H: HostHooks> Now<H> {
pub fn zoned_date_time_iso_with_provider(
self,
time_zone: Option<TimeZone>,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<ZonedDateTime> {
let system_nanoseconds = self.host_hooks.get_system_epoch_nanoseconds()?;
let time_zone = time_zone.unwrap_or(self.host_hooks.get_system_time_zone(provider)?);
Expand All @@ -67,7 +67,7 @@ impl<H: HostHooks> Now<H> {
pub fn plain_date_time_iso_with_provider(
self,
time_zone: Option<TimeZone>,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<PlainDateTime> {
let iso = self.system_datetime_with_provider(time_zone, provider)?;
Ok(PlainDateTime::new_unchecked(iso, Calendar::ISO))
Expand All @@ -80,7 +80,7 @@ impl<H: HostHooks> Now<H> {
pub fn plain_date_iso_with_provider(
self,
time_zone: Option<TimeZone>,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<PlainDate> {
let iso = self.system_datetime_with_provider(time_zone, provider)?;
Ok(PlainDate::new_unchecked(iso.date, Calendar::ISO))
Expand All @@ -93,7 +93,7 @@ impl<H: HostHooks> Now<H> {
pub fn plain_time_with_provider(
self,
time_zone: Option<TimeZone>,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<PlainTime> {
let iso = self.system_datetime_with_provider(time_zone, provider)?;
Ok(PlainTime::new_unchecked(iso.time))
Expand Down Expand Up @@ -148,7 +148,10 @@ mod tests {
}

impl HostTimeZone for TestHooks {
fn get_host_time_zone(&self, _: &impl TimeZoneProvider) -> TemporalResult<TimeZone> {
fn get_host_time_zone(
&self,
_: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<TimeZone> {
Ok(self.time_zone)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/core/plain_date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ impl PlainDate {
&self,
time_zone: TimeZone,
plain_time: Option<PlainTime>,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<ZonedDateTime> {
// NOTE (nekevss): Steps 1-4 are engine specific
let epoch_ns = if let Some(time) = plain_time {
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/core/plain_date_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ impl PlainDateTime {
&self,
time_zone: TimeZone,
disambiguation: Disambiguation,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<ZonedDateTime> {
// 6. Let epochNs be ? GetEpochNanosecondsFor(timeZone, dateTime.[[ISODateTime]], disambiguation).
let epoch_ns = time_zone.get_epoch_nanoseconds_for(self.iso, disambiguation, provider)?;
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/core/plain_month_day.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl PlainMonthDay {
pub fn epoch_ns_for_with_provider(
&self,
time_zone: TimeZone,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<EpochNanoseconds> {
// 2. Let isoDateTime be CombineISODateAndTimeRecord(temporalYearMonth.[[ISODate]], NoonTimeRecord()).
let iso = IsoDateTime::new(self.iso, IsoTime::noon())?;
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/core/plain_year_month.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ impl PlainYearMonth {
pub fn epoch_ns_for_with_provider(
&self,
time_zone: TimeZone,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<EpochNanoseconds> {
// 2. Let isoDateTime be CombineISODateAndTimeRecord(temporalYearMonth.[[ISODate]], NoonTimeRecord()).
let iso = IsoDateTime::new(self.iso, IsoTime::noon())?;
Expand Down
28 changes: 14 additions & 14 deletions src/builtins/core/time_zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl TimeZone {
#[inline]
pub(crate) fn from_time_zone_record(
record: TimeZoneRecord<Utf8>,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<Self> {
let timezone = match record {
TimeZoneRecord::Name(name) => TimeZone::IanaIdentifier(provider.get(name)?),
Expand All @@ -190,7 +190,7 @@ impl TimeZone {
/// Parses a `TimeZone` from a provided `&str`.
pub fn try_from_identifier_str_with_provider(
identifier: &str,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<Self> {
parse_identifier(identifier).map(|tz| match tz {
TimeZoneRecord::Name(name) => Ok(TimeZone::IanaIdentifier(provider.get(name)?)),
Expand All @@ -210,7 +210,7 @@ impl TimeZone {
/// This is the equivalent to [`ParseTemporalTimeZoneString`](https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaltimezonestring)
pub fn try_from_str_with_provider(
src: &str,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<Self> {
if let Ok(timezone) = Self::try_from_identifier_str_with_provider(src, provider) {
return Ok(timezone);
Expand All @@ -227,7 +227,7 @@ impl TimeZone {
/// Returns the current `TimeZoneSlot`'s identifier.
pub fn identifier_with_provider(
&self,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<String> {
Ok(match self {
TimeZone::IanaIdentifier(s) => provider.identifier(*s)?.into(),
Expand All @@ -244,7 +244,7 @@ impl TimeZone {
/// Get the primary identifier for this timezone
pub fn primary_identifier_with_provider(
&self,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<Self> {
Ok(match self {
TimeZone::IanaIdentifier(s) => TimeZone::IanaIdentifier(provider.canonicalized(*s)?),
Expand All @@ -262,7 +262,7 @@ impl TimeZone {
pub(crate) fn time_zone_equals_with_provider(
&self,
other: &Self,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<bool> {
Ok(match (self, other) {
(TimeZone::IanaIdentifier(one), TimeZone::IanaIdentifier(two)) => {
Expand All @@ -282,7 +282,7 @@ impl TimeZone {
}

/// Get the primary identifier for this timezone
pub fn utc_with_provider(provider: &impl TimeZoneProvider) -> Self {
pub fn utc_with_provider(provider: &(impl TimeZoneProvider + ?Sized)) -> Self {
Self::IanaIdentifier(provider.get(b"UTC").unwrap_or_default())
}
}
Expand All @@ -303,7 +303,7 @@ impl TimeZone {
pub(crate) fn get_iso_datetime_for(
&self,
instant: &Instant,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<IsoDateTime> {
// 1. Let offsetNanoseconds be GetOffsetNanosecondsFor(timeZone, epochNs).
let nanos = self.get_offset_nanos_for(instant.as_i128(), provider)?;
Expand All @@ -321,7 +321,7 @@ impl TimeZone {
pub(crate) fn get_offset_nanos_for(
&self,
utc_epoch: i128,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<i128> {
// 1. Let parseResult be ! ParseTimeZoneIdentifier(timeZone).
match self {
Expand All @@ -340,7 +340,7 @@ impl TimeZone {
pub(crate) fn get_utc_offset_for(
&self,
utc_epoch: i128,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<UtcOffset> {
let offset = self.get_offset_nanos_for(utc_epoch, provider)?;
let offset = i64::try_from(offset).ok().temporal_unwrap()?;
Expand All @@ -351,7 +351,7 @@ impl TimeZone {
&self,
local_iso: IsoDateTime,
disambiguation: Disambiguation,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<EpochNanosecondsAndOffset> {
// 1. Let possibleEpochNs be ? GetPossibleEpochNanoseconds(timeZone, isoDateTime).
let possible_nanos = self.get_possible_epoch_ns_for(local_iso, provider)?;
Expand All @@ -363,7 +363,7 @@ impl TimeZone {
pub(crate) fn get_possible_epoch_ns_for(
&self,
local_iso: IsoDateTime,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<CandidateEpochNanoseconds> {
// 1.Let parseResult be ! ParseTimeZoneIdentifier(timeZone).
let possible_nanoseconds = match self {
Expand Down Expand Up @@ -442,7 +442,7 @@ impl TimeZone {
nanos: CandidateEpochNanoseconds,
iso: IsoDateTime,
disambiguation: Disambiguation,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<EpochNanosecondsAndOffset> {
// 1. Let n be possibleEpochNs's length.
let valid_bounds = match nanos {
Expand Down Expand Up @@ -556,7 +556,7 @@ impl TimeZone {
pub(crate) fn get_start_of_day(
&self,
iso_date: &IsoDate,
provider: &impl TimeZoneProvider,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<EpochNanosecondsAndOffset> {
// 1. Let isoDateTime be CombineISODateAndTimeRecord(isoDate, MidnightTimeRecord()).
let iso = IsoDateTime::new_unchecked(*iso_date, IsoTime::default());
Expand Down
Loading