-
Notifications
You must be signed in to change notification settings - Fork 106
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
Add "AtTime" generators for V1, V6, and V7 #142
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #142 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 4 5 +1
Lines 513 453 -60
=========================================
- Hits 513 453 -60 ☔ View full report in Codecov by Sentry. |
Nice. Looks good so far. I think it was the right call to add some additional functions. As a mega nit, what do you think of the convention |
Personally, I like
All that said, I really don't care if you want to change it. |
@@ -360,7 +373,7 @@ func (g *Gen) NewV7() (UUID, error) { | |||
// When useUnixTSMs is false, it uses the Coordinated Universal Time (UTC) as a count of 100- | |||
// | |||
// nanosecond intervals since 00:00:00.00, 15 October 1582 (the date of Gregorian reform to the Christian calendar). | |||
func (g *Gen) getClockSequence(useUnixTSMs bool) (uint64, uint16, error) { | |||
func (g *Gen) getClockSequence(useUnixTSMs bool, atTime time.Time) (uint64, uint16, error) { |
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.
nit: The doc string for this method needs to be updated to reflect the new behavior
Unrelated to this PR, but it seems like the formatting of the comment is off. I don't think there's supposed to be a paragraph break between "100-" and "nanosecond".
@@ -418,8 +431,8 @@ func (g *Gen) getHardwareAddr() ([]byte, error) { | |||
|
|||
// Returns the difference between UUID epoch (October 15, 1582) | |||
// and current time in 100-nanosecond intervals. | |||
func (g *Gen) getEpoch() uint64 { | |||
return epochStart + uint64(g.epochFunc().UnixNano()/100) | |||
func (g *Gen) getEpoch(atTime time.Time) uint64 { |
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.
Same nit here. Please update the doc string to reflect the new behavior.
@kohenkatz Dependabot updated the go-setup github action, and I noted we were testing against older versions of go so I took the opportunity to kick them up to latest and latest -1. Might be worth rebasing against master :) |
This PR implements the request in #84 to be able to create UUIDs at specific known timestamps, in addition to the current time.
Although that request only mentions UUIDv1, this PR also includes the other two time-based UUID versions, namely v6 and v7.
To prevent code duplication, this PR reimplements
NewV1
,NewV6
, andNewV7
to each call their respectiveNewV<X>AtTime
with the providedEpochFunc
, which defaults to providing the current time.This PR will remain a draft until I have time to write some tests...