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

feat: Update Timestamp Constructor with nanoseconds #27

Merged

Conversation

KKimj
Copy link
Contributor

@KKimj KKimj commented Mar 8, 2024

Hello!

This update enables preservation of nanoseconds below 1000, addressing the issue where fractions of milliseconds were being discarded.
image

Thanks!

@CLAassistant
Copy link

CLAassistant commented Mar 8, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@rrousselGit rrousselGit left a comment

Choose a reason for hiding this comment

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

There's some value to it.

Could you add tests for this constructor? Since it's now public.
And add dartdocs for it too.

@KKimj
Copy link
Contributor Author

KKimj commented Jul 13, 2024

@rrousselGit

Hello! : )
I've added some docstrings and test code for Timestamp.
Please let me know if you have any feedback. Thank you!

@KKimj
Copy link
Contributor Author

KKimj commented Jul 13, 2024

///
/// Returns a new [Timestamp] representing the same point in time
/// as the given number of microseconds.
factory Timestamp.fromMicros(int microseconds) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This one needs a test too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! Thanks : )

Copy link
Member

Choose a reason for hiding this comment

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

Is this constructor necessary? It makes sense to stick as close to the JavaScript implementation as possible imo, and I don't believe this exists there (could be wrong)

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 believe the Timestamp.fromMicros constructor is necessary. Considering the Dart native environment, the lack of this constructor would result in the loss of microsecond precision.

Additionally, while the microsecondsSinceEpoch property of the Dart DateTime API is available in the web environment, the limitations of JavaScript mean that there will still be a loss of precision in the microsecond unit.

Even though a code like

Timestamp.fromMicros(DateTime.now().microsecondsSinceEpoch);

would not throw an error

Copy link
Member

Choose a reason for hiding this comment

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

Interesting, thanks for the insight. I'd much prefer the name to be fromMicroseconds, but leave that one to Remi to call :D

Copy link

codecov bot commented Jul 19, 2024

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

Copy link
Collaborator

@rrousselGit rrousselGit left a comment

Choose a reason for hiding this comment

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

LGTM thanks!

@rrousselGit rrousselGit merged commit c4e1493 into invertase:main Jul 22, 2024
5 checks passed
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.

4 participants