-
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 7 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 |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| use crate::{builtins::TZ_PROVIDER, TemporalError, TemporalResult, Date}; | ||
|
|
||
| impl Date { | ||
|
|
||
| /// Converts a `Date` to a `ZonedDateTime` in the UTC time zone. | ||
| pub fn to_zoned_date_time (self, time_zone: &str) -> TemporalResult<crate::ZonedDateTime> { | ||
|
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: function signature here should be the same as 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) | ||
|
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: |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)?; | ||
|
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(&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) | ||
|
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 ==== | ||
|
|
||
There was a problem hiding this comment.
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