Skip to content
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

Builtin Date_Time, Time_Of_Day, Zone #3658

Merged
merged 13 commits into from
Aug 24, 2022
Merged

Conversation

hubertp
Copy link
Contributor

@hubertp hubertp commented Aug 18, 2022

Pull Request Description

Improved polyglot support for Date_Time (formerly Time), Time_Of_Day and
Zone. This follows the pattern introduced for Enso Date.

Related to https://www.pivotaltracker.com/story/show/182973664 and https://www.pivotaltracker.com/n/projects/2539304/stories/182987210

Important Notes

Minor caveat - in tests for Date, had to bend a lot for JS Date to pass.
This is because JS Date is not really only a Date, but also a Time and
Timezone, previously we just didn't consider the latter.
Also, JS Date does not deal well with setting timezones so the trick I
used is to first call foreign function returning a polyglot JS Date,
which is converted to ZonedDateTime and only then set the correct
timezone. That way none of the existing tests had to be changed or
special cased.

Additionally, JS deals with milliseconds rather than nanoseconds so
there is loss in precision, as noted in Time_Spec.

Checklist

Please include the following checklist in your PR:

  • The documentation has been updated if necessary.
  • All code conforms to the
    Scala,
    Java,
    and
    Rust
    style guides.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed: Enso GUI was tested when built using BOTH
      ./run ide build and ./run ide watch.

Copy link
Member

@JaroslavTulach JaroslavTulach 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 to me overall. Some observations inline.

@hubertp hubertp force-pushed the wip/hubert/datetime-182973664 branch from 0434f47 to 7a11d4d Compare August 19, 2022 08:57
@hubertp hubertp marked this pull request as ready for review August 19, 2022 08:57
@hubertp hubertp force-pushed the wip/hubert/datetime-182973664 branch from 0df919c to 7802603 Compare August 23, 2022 09:26
Comment on lines -174 to 181
Integer -> self.make_integer_parser
Decimal -> self.make_decimal_parser
Boolean -> self.make_boolean_parser
_ ->
if datatype == Date then self.make_date_parser else
if datatype == Time then self.make_datetime_parser else
if datatype == Time_Of_Day then self.make_time_parser else
Error.throw (Illegal_Argument_Error "Unsupported datatype: "+datatype.to_text)
Integer -> self.make_integer_parser
Decimal -> self.make_decimal_parser
Boolean -> self.make_boolean_parser
Date -> self.make_date_parser
Date_Time -> self.make_datetime_parser
Time_Of_Day -> self.make_time_parser
_ -> Error.throw (Illegal_Argument_Error "Unsupported datatype: "+datatype.to_text)

Copy link
Member

Choose a reason for hiding this comment

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

❤️

hubertp and others added 10 commits August 23, 2022 17:22
Improved polyglot support for Date_Time (formerly Time), Time_Of_Day and
Zone. This follows the pattern introduced for Enso Date.

Minor caveat - in tests for Date, had to bend a lot for JS Date to pass.
This is because JS Date is not really only a Date, but also a Time and
Timezone, previously we just didn't consider the latter.
Also, JS Date does not deal well with setting timezones so the trick I
used is to first call foreign function returning a polyglot JS Date,
which is converted to ZonedDateTime and only then set the correct
timezone. That way none of the existing tests had to be changes or
special cased.

Additionally, JS deals with milliseconds rather than nanoseconds so
there is loss in precision, as noted in Time_Spec.
Column reader didn't take into account timezone but that was a mistake
since then it wouldn't map to Enso's Date_Time.
Added tests that check it now.
Co-authored-by: Radosław Waśko <radoslaw.wasko@enso.org>
@hubertp hubertp force-pushed the wip/hubert/datetime-182973664 branch from bee9a17 to c761487 Compare August 23, 2022 15:22
@hubertp hubertp requested a review from radeusgd August 23, 2022 15:57
@hubertp
Copy link
Contributor Author

hubertp commented Aug 23, 2022

@radeusgd I think I addressed all your comments

}

@Builtin.Method(description = "Return the number of seconds from the Unix epoch.")
public long toEpochSeconds() {
Copy link
Member

Choose a reason for hiding this comment

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

My recent experience with @TruffleBoundary suggests that many of these methods shall be behind the boundary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can add some, but at the moment without any gatekeepers it feels like a slightly random process.

Copy link
Member

@jdunkerley jdunkerley left a comment

Choose a reason for hiding this comment

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

Thanks for this @hubertp - this gives us a fantastic base to build on to build out the functions we need.

@hubertp hubertp merged commit d87a32d into develop Aug 24, 2022
@hubertp hubertp deleted the wip/hubert/datetime-182973664 branch August 24, 2022 10:31
@wdanilo wdanilo mentioned this pull request Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants