-
Notifications
You must be signed in to change notification settings - Fork 43
initial implementation of ToZonedDateTime, ToPlainDate, ToPlainTime #244
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
77d5906
initial implementation of toZonedDateTime, toPlainDate, toPlainTime
lockels 72d3515
cargo clippy
lockels 468782a
to_zoned_date_time implementation in compiled
lockels b80d6f2
to_plain_date temporal_capi implementation for FFI
lockels f5d625f
cpp
lockels File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,18 +2,19 @@ | |
|
|
||
| use super::{ | ||
| duration::normalized::{NormalizedDurationRecord, NormalizedTimeDuration}, | ||
| Duration, PartialDate, PartialTime, PlainDate, PlainTime, | ||
| Duration, PartialDate, PartialTime, PlainDate, PlainTime, ZonedDateTime, | ||
| }; | ||
| use crate::{ | ||
| builtins::core::{calendar::Calendar, Instant}, | ||
| iso::{IsoDate, IsoDateTime, IsoTime}, | ||
| options::{ | ||
| ArithmeticOverflow, DifferenceOperation, DifferenceSettings, DisplayCalendar, | ||
| ResolvedRoundingOptions, RoundingOptions, TemporalUnit, ToStringRoundingOptions, UnitGroup, | ||
| ArithmeticOverflow, DifferenceOperation, DifferenceSettings, Disambiguation, | ||
| DisplayCalendar, ResolvedRoundingOptions, RoundingOptions, TemporalUnit, | ||
| ToStringRoundingOptions, UnitGroup, | ||
| }, | ||
| parsers::{parse_date_time, IxdtfStringBuilder}, | ||
| primitive::FiniteF64, | ||
| provider::NeverProvider, | ||
| provider::{NeverProvider, TimeZoneProvider}, | ||
| temporal_assert, MonthCode, TemporalError, TemporalResult, TemporalUnwrap, TimeZone, | ||
| }; | ||
| use alloc::string::String; | ||
|
|
@@ -682,8 +683,33 @@ impl PlainDateTime { | |
| Ok(Self::new_unchecked(result, self.calendar.clone())) | ||
| } | ||
|
|
||
| pub fn to_zoned_date_time_with_provider( | ||
| &self, | ||
| time_zone: &TimeZone, | ||
| disambiguation: Disambiguation, | ||
| provider: &impl TimeZoneProvider, | ||
| ) -> TemporalResult<ZonedDateTime> { | ||
| // 6. Let epochNs be ? GetEpochNanosecondsFor(timeZone, dateTime.[[ISODateTime]], disambiguation). | ||
| let epoch_ns = time_zone.get_epoch_nanoseconds_for(self.iso, disambiguation, provider)?; | ||
| // 7. Return ! CreateTemporalZonedDateTime(epochNs, timeZone, dateTime.[[Calendar]]). | ||
| Ok(ZonedDateTime::new_unchecked( | ||
| Instant::from(epoch_ns), | ||
| self.calendar.clone(), | ||
| time_zone.clone(), | ||
| )) | ||
| } | ||
|
|
||
| pub fn to_plain_date(&self) -> TemporalResult<PlainDate> { | ||
|
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. nit: add a temporal_capi implementation of This one may be a little harder because it's dealing with the diplomat bindings, but maybe you can take a crack at it. Changes should be made here. |
||
| // 3. Return ! CreateTemporalDate(dateTime.[[ISODateTime]].[[ISODate]], dateTime.[[Calendar]]). | ||
| Ok(PlainDate::new_unchecked( | ||
| self.iso.date, | ||
| self.calendar.clone(), | ||
| )) | ||
| } | ||
|
|
||
| pub fn to_plain_time(&self) -> TemporalResult<PlainTime> { | ||
| Err(TemporalError::general("Not yet implemented.")) | ||
| // 3. Return ! CreateTemporalTime(dateTime.[[ISODateTime]].[[Time]]). | ||
| Ok(PlainTime::new_unchecked(self.iso.time)) | ||
| } | ||
|
|
||
| pub fn to_ixdtf_string( | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: add a
PlainDateTime::to_zoned_date_timeimplementation onPlainDateTimein compiled.It looks like I missed adding this stub. So a new module should be added to the compiled directory for
PlainDateTimeand the companion method added.Worthwhile note: there's no current need to add this method to
temporal_capijust yet because time zone providers over the FFI is still a work in progress. So only the non provider method implementation is needed.