Skip to content

Updates to instant and its methods #85

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 5 commits into from
Jul 19, 2024
Merged

Conversation

nekevss
Copy link
Member

@nekevss nekevss commented Jul 19, 2024

This PR updates Instant to some of the newer specification changes.

TLDR of the below:

  • Updates Instant struct
  • Updates diffing ops and adds tests
  • Implements FromStr.

Primarily, it brings since and until up to date with both temporal_rs and the specification as a whole (along with at least 2 basic tests for since and until)

This PR also changes Instant inner nanoseconds from BigInt to i128. My thought is to eventually remove all usage of BigInt from temporal_rs in general. Primarily motivated by the thought that if NormalizedTimeDuration is using a i128, I don't see a huge reason why Instant should differ, unless I'm overlooking something and someone thinks otherwise.

Finally, it implements FromStr for Instant. This will allow parsing of JsString in Boa, and would unblock to_temporal_instant.

// `temporal_unwraps` MUST be present.

// Find the IsoDate
let date = ixdtf_record.date.temporal_unwrap()?;
Copy link
Member

@jedel1043 jedel1043 Jul 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, is this asserting an invariant? Because temporal_unwrap should only be used to ensure invariants are preserved. If this is used to unwrap errors caused by the user, then I think it should return an error instead, which is a bit more explanatory.

Copy link
Member Author

@nekevss nekevss Jul 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be an invariant at this point. parse_instant requires a string with a DateRecord, TimeRecord, and OffsetRecord, and throws an error if any of them are None, which is what the NOTE was trying to highlight. 😆 Although reading it back now, the note probably makes it more ambiguous.

We can return an error in these places again, but they would be redundant errors that realistically would never throw.

Copy link
Member

@jedel1043 jedel1043 Jul 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, now I see why. On parse_instant, we validate that the fields are Some and throw otherwise. Can we move that invariant to the typesystem? Instead of returning an IxdtfParseRecord, we return IxdtfParseInstantRecord with the validated fields being not Option.

@nekevss nekevss added C-enhancement New feature or request C-internal Internal library improvements labels Jul 19, 2024
Copy link
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@nekevss nekevss merged commit 8ef18fe into main Jul 19, 2024
5 checks passed
@nekevss nekevss deleted the update-instant-component branch July 21, 2024 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement New feature or request C-internal Internal library improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants