Skip to content

Commit 66769cd

Browse files
committed
fix: incorrect timestamp in UUIDv7 when using user-specified instant #107
1 parent e2e75c0 commit 66769cd

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ All notable changes to this project will be documented in this file.
66

77
Nothing unreleased.
88

9+
## [6.1.1] - 2025-04-13
10+
11+
- Fixed incorrect timestamp in UUIDv7 when using user-specified instant. #107
12+
913
## [6.1.0] - 2025-03-29
1014

1115
- Added microsecond precision to UUIDv7;
@@ -418,7 +422,8 @@ Remove `Fingerprint` // too complex
418422
- Removed UuidSettings.getNodeIdentifierDeprecated // remove deprecated
419423
- Renamed UuidSettings to UuidCreatorSettings
420424

421-
[unreleased]: https://github.com/f4b6a3/uuid-creator/compare/uuid-creator-6.1.0...HEAD
425+
[unreleased]: https://github.com/f4b6a3/uuid-creator/compare/uuid-creator-6.1.1...HEAD
426+
[6.1.1]: https://github.com/f4b6a3/uuid-creator/compare/uuid-creator-6.1.0...uuid-creator-6.1.1
422427
[6.1.0]: https://github.com/f4b6a3/uuid-creator/compare/uuid-creator-6.0.0...uuid-creator-6.1.0
423428
[6.0.0]: https://github.com/f4b6a3/uuid-creator/compare/uuid-creator-5.3.7...uuid-creator-6.0.0
424429
[5.3.7]: https://github.com/f4b6a3/uuid-creator/compare/uuid-creator-5.3.6...uuid-creator-5.3.7

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Maven:
4444
<dependency>
4545
<groupId>com.github.f4b6a3</groupId>
4646
<artifactId>uuid-creator</artifactId>
47-
<version>6.1.0</version>
47+
<version>6.1.1</version>
4848
</dependency>
4949
```
5050

src/main/java/com/github/f4b6a3/uuid/factory/standard/TimeOrderedEpochFactory.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public static Builder builder() {
255255
*/
256256
@Override
257257
public UUID create() {
258-
UUID uuid = this.uuidFunction.apply(instantFunction.get());
258+
UUID uuid = this.uuidFunction.apply(null);
259259
return toUuid(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
260260
}
261261

@@ -308,18 +308,25 @@ public UUID apply(final Instant instant) {
308308
lock.lock();
309309
try {
310310

311+
if (instant != null) {
312+
reset(instant); // user specified
313+
return new UUID(this.msb, this.lsb);
314+
}
315+
316+
Instant now = instantFunction.get();
317+
311318
long lastTime = this.lastTime();
312-
long time = instant.toEpochMilli();
319+
long time = now.toEpochMilli();
313320

314321
// is it not too much ahead of system clock?
315322
if (advanceMax > Math.abs(lastTime - time)) {
316323
time = Math.max(lastTime, time);
317324
}
318325

319326
if (time == lastTime) {
320-
increment(instant);
327+
increment(now);
321328
} else {
322-
reset(instant);
329+
reset(now);
323330
}
324331

325332
return new UUID(this.msb, this.lsb);

0 commit comments

Comments
 (0)