Skip to content

Commit

Permalink
Fix timestamp prefix in UUIDv7
Browse files Browse the repository at this point in the history
  • Loading branch information
hfhbd committed Oct 31, 2023
1 parent dda2f01 commit 89e10ea
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/UUID7.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ private const val UNIX_48_TIMESTAMP = 0x1FFF_FFFF_FFFF_FL
@UUIDExperimentalAPI
public fun UUIDv7(timeStamp: Long, random: Random = SecureRandom): UUID {
require(timeStamp <= UNIX_48_TIMESTAMP) {
"timeStamp $timeStamp must be 48 bits, was $timeStamp."
"timeStamp $timeStamp must be <= 48 bits, was $timeStamp."
}
val leftTimeStamp = timeStamp shl 16
val rand_a = (random.nextInt() shr 20).toLong()
val rand_a = random.nextBits(12).toLong()

Check warning

Code scanning / detekt

Variable names should follow the naming convention set in the projects configuration. Warning

Variable names should match the pattern: [a-z][A-Za-z0-9]*

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
val timeStampAndVersionRaw = (leftTimeStamp or rand_a) and -0xf001L or 0x7000L

// set variant to 4 or 5
Expand Down

0 comments on commit 89e10ea

Please sign in to comment.