-
Notifications
You must be signed in to change notification settings - Fork 43
Implement toZonedDateTime in PlainDate #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
3fd2fa3
ba8c8ab
48fcbb6
f769e2a
d1556af
4d5fbca
9c1752a
9a80a4d
e5e4e60
03a5bdd
4147b16
292b00a
deb7cc1
49072bf
cb6550c
4c2ce7b
a9b0747
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -600,8 +600,52 @@ impl PlainDate { | |
| .with_calendar(self.calendar.identifier(), display_calendar) | ||
| .build() | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn to_zoned_date_time( | ||
| &self, | ||
| tz: TimeZone, | ||
| pt: Option<PlainTime>, | ||
|
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 { | ||
|
nekevss marked this conversation as resolved.
Outdated
|
||
| let temporal_time = Time::new_unchecked(time)?; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.