Skip to content

RUST-2256 feat: Add integration with jiff::Timestamp #587

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 3 commits into from
Aug 1, 2025

Conversation

Guara92
Copy link
Contributor

@Guara92 Guara92 commented Jul 31, 2025

feat: Add interoperability with jiff::Timestamp

Hi!
This PR introduces interoperability with the jiff (docs) crate by adding helpers to convert between jiff::Timestamp and bson::DateTime. This allows users of jiff, a modern and standards-focused time library, to seamlessly serialize and deserialize timestamps with BSON, I followed the already present integration with chrono to add features and tests.

Changes included:

  • Optional Dependency: Added jiff as an optional dependency under the jiff-0_2 feature flag.
  • Serde Helper: Created a new serde_with helper, datetime::FromJiff02Timestamp, to enable ergonomic serialization for structs (e.g., #[serde_as(as = "datetime::FromJiff02Timestamp")]).
  • Direct Conversions: Added DateTime::from_jiff() and DateTime::to_jiff() for direct, manual conversions between the two types.
  • Tests: Added tests equivalent to the chrono ones

Let me know if I missed anything!

@Guara92 Guara92 requested a review from a team as a code owner July 31, 2025 10:02
@Guara92 Guara92 requested a review from isabelatkinson July 31, 2025 10:03
@Guara92 Guara92 changed the title Add integration with jiff::Timestamp feat: Add integration with jiff::Timestamp Jul 31, 2025
@abr-egn abr-egn requested review from abr-egn and removed request for isabelatkinson July 31, 2025 10:06
abr-egn
abr-egn previously approved these changes Jul 31, 2025
Copy link
Contributor

@abr-egn abr-egn 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 the contribution - this looks good to me! I appreciate the care to follow the existing conventions of the bson crate 🙂. I've authorized the test run, assuming that's green I'll merge this in!

@abr-egn
Copy link
Contributor

abr-egn commented Jul 31, 2025

Looks like one of the tests isn't compiling:

[2025/07/31 06:31:51.209] error[E0061]: this function takes 1 argument but 2 arguments were supplied
[2025/07/31 06:31:51.209]    --> src/tests/modules/serializer_deserializer.rs:331:15
[2025/07/31 06:31:51.209]     |
[2025/07/31 06:31:51.209] 331 |     let src = jiff::Timestamp::from_second(1_286_705_410, 0).unwrap();
[2025/07/31 06:31:51.209]     |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                - unexpected argument #2 of type `{integer}`
[2025/07/31 06:31:51.209]     |
[2025/07/31 06:31:51.209] note: associated function defined here
[2025/07/31 06:31:51.209]    --> /home/ubuntu/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/jiff-0.2.15/src/timestamp.rs:619:12
[2025/07/31 06:31:51.209]     |
[2025/07/31 06:31:51.209] 619 |     pub fn from_second(second: i64) -> Result<Timestamp, Error> {
[2025/07/31 06:31:51.209]     |            ^^^^^^^^^^^

@Guara92
Copy link
Contributor Author

Guara92 commented Jul 31, 2025

serializer_deserializer

oops, my bad, I fixed another copy&paste error in one test

@abr-egn abr-egn requested a review from isabelatkinson July 31, 2025 15:57
Copy link
Contributor

@isabelatkinson isabelatkinson 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 the contribution!

@isabelatkinson isabelatkinson merged commit 4ddf9fc into mongodb:main Aug 1, 2025
11 checks passed
@abr-egn abr-egn changed the title feat: Add integration with jiff::Timestamp RUST-2256 feat: Add integration with jiff::Timestamp Aug 1, 2025
@Guara92 Guara92 deleted the feat/add-jiff-support branch August 1, 2025 15:55
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