Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
44 changes: 44 additions & 0 deletions src/builtins/core/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,52 @@ impl PlainDate {
.with_calendar(self.calendar.identifier(), display_calendar)
.build()
}

#[inline]
pub fn to_zoned_date_time(
Comment thread
nekevss marked this conversation as resolved.
Outdated
&self,
tz: TimeZone,
pt: Option<PlainTime>,
Comment thread
nekevss marked this conversation as resolved.
Outdated
provider: &impl TimeZoneProvider
) -> TemporalResult<ZonedDateTime> {
//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).
// 7. Return ! CreateTemporalZonedDateTime(epochNs, timeZone, temporalDate.[[Calendar]]).

let result_iso = if let Some(time) = pt {
Comment thread
nekevss marked this conversation as resolved.
Outdated
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_unchecked(&self.iso, temporal_time.iso);
} else {
IsoDateTime::new_unchecked(&self.iso, IsoTime::default());
};

let epoch_ns = tz.get_epoch_nanoseconds_for(result_iso, Disambiguation::Compatible, provider)?;


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 ====

impl From<PlainDateTime> for PlainDate {
Expand Down
2 changes: 2 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,5 @@ pub(crate) fn iso_days_in_month(year: i32, month: i32) -> u8 {
// 12.2.40 `ToISODayOfWeek ( year, month, day )`

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

pub(crate) fn IsTemporalObject
Comment thread
nekevss marked this conversation as resolved.
Outdated