Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
12 changes: 12 additions & 0 deletions src/builtins/compiled/date.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::{builtins::TZ_PROVIDER, TemporalError, TemporalResult, Date};

impl Date {
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.

issue: wrong struct name on the impl block -> PlainDate


/// Converts a `Date` to a `ZonedDateTime` in the UTC time zone.
pub fn to_zoned_date_time (self, time_zone: &str) -> TemporalResult<crate::ZonedDateTime> {
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.

issue: function signature here should be the same as to_zoned_date_time_with_provider.

Also, it looks like there is a space after the function name. Although, I'm not entirely sure whether that may affect anything.

let provider = TZ_PROVIDER
.lock()
.map_err(|_| TemporalError::general("Unable to acquire lock"))?;
self.to_zoned_date_time_with_provider(time_zone, &*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.

issue: to_zoned_date_time_with_provider is called with the wrong args.

self.to_zoned_date_time_with_provider(time_zone, plain_time, &*provider)

}
}
39 changes: 39 additions & 0 deletions src/builtins/core/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,45 @@ impl PlainDate {
.with_calendar(self.calendar.identifier(), display_calendar)
.build()
}

#[inline]
pub fn to_zoned_date_time_with_provider(
&self,
tz: TimeZone,
plain_time: Option<PlainTime>,
provider: &impl TimeZoneProvider
) -> TemporalResult<ZonedDateTime> {
// 1. Let temporalDate be the this value.
// 2. Perform ? RequireInternalSlot(temporalDate, [[InitializedTemporalDate]]).
//3. If item is an Object, then
//a. Let timeZoneLike be ? Get(item, "timeZone").
//b. If timeZoneLike is undefined, then
// i. Let timeZone be ? ToTemporalTimeZoneIdentifier(item).
// ii. Let temporalTime be undefined.
// c. Else,
// i. Let timeZone be ? ToTemporalTimeZoneIdentifier(timeZoneLike).
// ii. Let temporalTime be ? Get(item, "plainTime").
// 4. Else,
// a. Let timeZone be ? ToTemporalTimeZoneIdentifier(item).
// b. Let temporalTime be undefined.

// 5. If temporalTime is undefined, then
// a. Let epochNs be ? GetStartOfDay(timeZone, temporalDate.[[ISODate]]).
// 6. Else,
// a. Set temporalTime to ? ToTemporalTime(temporalTime).
// b. Let isoDateTime be CombineISODateAndTimeRecord(temporalDate.[[ISODate]], temporalTime.[[Time]]).
// c. If ISODateTimeWithinLimits(isoDateTime) is false, throw a RangeError exception.
// d. Let epochNs be ? GetEpochNanosecondsFor(timeZone, isoDateTime, compatible).
let epoch_ns = if let Some(time) = plain_time {
let temporal_time = Time::new_unchecked(time)?;
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.

issue: I'm not entirely sure what the time is referring to here. But it should be unneeded.

You should be able to access PlainTime's iso field by using time.iso in line 685.

IsoDateTime::new(&self.iso, temporal_time.iso);
tz.get_epoch_nanoseconds_for(result_iso, Disambiguation::Compatible, provider)?;
} else {
tz.get_start_of_day(self.iso, provider)?;
};

// 7. Return ! CreateTemporalZonedDateTime(epochNs, timeZone, temporalDate.[[Calendar]]).
Self::try_new(epoch_ns.0, self.calendar.clone(), tz)
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.

issue: missing bracket to close function

}

// ==== Trait impls ====
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,4 @@ pub(crate) fn iso_days_in_month(year: i32, month: u8) -> u8 {
// 12.2.39 `ToISODayOfYear ( year, month, day )`
// 12.2.40 `ToISODayOfWeek ( year, month, day )`

// ==== End Calendar Equations ====
// ==== End Calendar Equations ====