Skip to content

Conversation

@dcormier
Copy link
Contributor

Closes #834.

src/timestamp.rs Outdated
#[cfg(all(
feature = "std",
not(miri),
any(
Copy link
Member

Choose a reason for hiding this comment

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

I think we shouldn't need to cfg out these impls on wasm32-unknown-unknown. The value of UNIX_EPOCH on wasm32-unknown-unknown is meaningless, but you also can't construct a SystemTime anyways, so I think leaving these impls is ok, and will be less likely to result in impossible build failures for anyone targeting multiple platforms.

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've updated the PR with those adjustments.

src/timestamp.rs Outdated
}
}

#[cfg(all(feature = "std", not(miri), not(feature = "js")))]
Copy link
Member

Choose a reason for hiding this comment

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

I think the js feature is likely also unnecessary here. Since it's a no-op outside of wasm32-unknown-unknown, its presence shouldn't have any impact on std-code.

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.

@KodrAus
Copy link
Member

KodrAus commented Aug 6, 2025

Ah, mismatched_lifetime_syntaxes strikes again. I'll submit a PR to fix all that up

@KodrAus
Copy link
Member

KodrAus commented Aug 6, 2025

The failure appears to be here:

 failures:
  
  ---- timestamp::test_conversion::from_system_time stdout ----
  
  thread 'timestamp::test_conversion::from_system_time' panicked at src\timestamp.rs:1251:9:
  assertion `left == right` failed
    left: Timestamp { seconds: 1501520400, subsec_nanos: 1, counter: 0, usable_counter_bits: 0 }
   right: Timestamp { seconds: 1501520400, subsec_nanos: 0, counter: 0, usable_counter_bits: 0 }
  
  ---- timestamp::test_conversion::from_system_time_before_epoch stdout ----
  
  thread 'timestamp::test_conversion::from_system_time_before_epoch' panicked at src\timestamp.rs:1260:43:
  called `Result::unwrap_err()` on an `Ok` value: Timestamp { seconds: 0, subsec_nanos: 0, counter: 0, usable_counter_bits: 0 }

@KodrAus
Copy link
Member

KodrAus commented Aug 6, 2025

This could be Window's 100ns system time granularity? We could try updating the test case to use 100 nanos instead of just 1.

@KodrAus
Copy link
Member

KodrAus commented Aug 6, 2025

The WASI failure appears to be in the from_system_time_before_epoch test case:

          12:  0x8cded - uuid-6d0d58a3e0a20e3c.wasm!core::option::unwrap_failed::hf7f62ca5847d7f2d
          13:  0x26bd3 - uuid-6d0d58a3e0a20e3c.wasm!uuid::timestamp::test_conversion::from_system_time_before_epoch::h038bbadfcb94bfb7
          14:  0x2a43f - uuid-6d0d58a3e0a20e3c.wasm!uuid::timestamp::test_conversion::from_system_time_before_epoch::{{closure}}::h42d9040da4fb3cc8

@dcormier
Copy link
Contributor Author

dcormier commented Aug 6, 2025

This could be Window's 100ns system time granularity? We could try updating the test case to use 100 nanos instead of just 1.

Ah, that may be. I've updated the test cases to use 1µs resolution.

@dcormier
Copy link
Contributor Author

dcormier commented Aug 6, 2025

The WASI failure is curious. I'd like to see if that test output changes with that latest commit (which should at least resolve the Windows issue). I'll also see about running that test locally so I can iterate on it without it having to go through CI, if needed.

I wonder if UNIX_EPOCH has a different value when compiled for WASI?


Edit: I'm able to reproduce it locally. This returns None on WASI:

SystemTime::UNIX_EPOCH.checked_sub(Duration::from_nanos(1_000))

I'll poke around some more because I'm not familiar with this environment, but perhaps this test should be excluded on that platform?


Edit 2: A SystemTime on WASI simply holds a Duration, which stores unsigned values. So, a WASI SystemTime currently cannot be before UNIX_EPOCH.

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
pub struct SystemTime(Duration);

pub const UNIX_EPOCH: SystemTime = SystemTime(Duration::from_secs(0));
#[stable(feature = "duration", since = "1.3.0")]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[rustc_diagnostic_item = "Duration"]
pub struct Duration {
    secs: u64,
    nanos: Nanoseconds, // Always 0 <= nanos < NANOS_PER_SEC
}
define_valid_range_type! {
    pub struct Nanoseconds(u32 as u32 in 0..=999_999_999);
}

My proposed solution (and the one I've updated this PR with) is to have that test gracefully exit when the platform running it does not support values < UNIX_EPOCH. Thoughts?

Copy link
Member

@KodrAus KodrAus 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 working through this @dcormier!

This looks good to me 🙇

@KodrAus KodrAus merged commit 87a4359 into uuid-rs:main Aug 8, 2025
22 checks passed
@dcormier
Copy link
Contributor Author

dcormier commented Aug 8, 2025

Thank you! Much appreciated.

kodiakhq bot pushed a commit to pdylanross/fatigue that referenced this pull request Aug 12, 2025
Bumps uuid from 1.17.0 to 1.18.0.

Release notes
Sourced from uuid's releases.

v1.18.0
What's Changed

Fix up mismatched_lifetime_syntaxes lint by @​KodrAus in uuid-rs/uuid#837
Conversions between Timestamp and std::time::SystemTime by @​dcormier in uuid-rs/uuid#835
Wrap the error type used in time conversions by @​KodrAus in uuid-rs/uuid#838
Prepare for 1.18.0 release by @​KodrAus in uuid-rs/uuid#839

New Contributors

@​dcormier made their first contribution in uuid-rs/uuid#835

Full Changelog: uuid-rs/[email protected]



Commits

60a49eb Merge pull request #839 from uuid-rs/cargo/v1.18.0
eb8c697 prepare for 1.18.0 release
281f26f Merge pull request #838 from uuid-rs/chore/time-conversion
2d67ab2 don't use allocated values in errors
c284ed5 wrap the error type used in time conversions
87a4359 Merge pull request #835 from dcormier/main
8927396 Merge pull request #837 from uuid-rs/fix/lifetime-syntaxes
6dfb4b1 Conversions between Timestamp and std::time::SystemTime
b508383 fix up mismatched_lifetime_syntaxes lint
See full diff in compare view




Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options

You can trigger Dependabot actions by commenting on this PR:

@dependabot rebase will rebase this PR
@dependabot recreate will recreate this PR, overwriting any edits that have been made to it
@dependabot merge will merge this PR after your CI passes on it
@dependabot squash and merge will squash and merge this PR after your CI passes on it
@dependabot cancel merge will cancel a previously requested merge and block automerging
@dependabot reopen will reopen this PR if it is closed
@dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
@dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency
@dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
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.

It would be nice to have conversions between std::time::SystemTime and Timestamp

2 participants