-
Notifications
You must be signed in to change notification settings - Fork 377
feat: add option for using Temporal timestamp representation #1219
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
feat: add option for using Temporal timestamp representation #1219
Conversation
stephenh
left a comment
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.
Love to see temporal support; thank you @confusingstraw !
Looks like there was a lint error; can you take a look at that, and then I'll hit merge?
|
Should be fixed. Hopefully adding a global type polyfill for the integration test environment is acceptable. |
|
Yep, lgtm; thank you! |
# [2.8.0](v2.7.7...v2.8.0) (2025-10-21) ### Features * add option for using Temporal timestamp representation ([#1219](#1219)) ([c46c020](c46c020))
|
🎉 This issue has been resolved in version 2.8.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This PR fixes an issue I introduced in the initial `useDate=temporal` PR [here](#1219). The generated code for `toTimestamp` was dividing the `epochMilliseconds` twice, causing the date to get truncated to `1970-01-01`, so the tests would seem to work for dates. There was _also_ a bug in how `nanos` was calculated: ```typescript Temporal.Instant .fromEpochMilliseconds(instant.epochMilliseconds) .until(instant); ``` since we were deriving the start date from `epochMilliseconds`, so the remainder only included micro/nanoseconds (milliseconds were always `000`). The PR addresses the first issue by ensuring we only divide once, in the generated `seconds` code. It fixes the latter by using the built-in [Temporal.Instant.prototype.round](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/round) method to round to the nearest second without needing to do any explicit math. Lastly, it also updates the tests, as the `toStrictEqual` check was succeeding even for `Instant`s whose string representations were clearly different, so now we will test against the output string.
This PR adds support for a new
useDateoption:temporal. When used, it will cause the generated code to use the new Temporal.Instant object.The advantages of supporting the new API include higher precision timestamps (up to nanosecond precision, which aligns with the Protobuf spec), as well as a variety of Temporal-related utilities, such as Duration. In a future update, it may be useful to add a similar flag for using the
Temporal.Durationobject forDurationrepresentation.