aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeoramund <161657516+Feoramund@users.noreply.github.com>2024-06-22 17:58:42 -0400
committerFeoramund <161657516+Feoramund@users.noreply.github.com>2024-06-22 18:21:32 -0400
commit8a4a3ed66e9fc2e4ecc398acb616a6c3b756515e (patch)
tree5940668acca54ab02cf4827cb1fb106e9ffca4aa
parent4481f9c695061782f8ff086fc13c58f13ab43023 (diff)
Change how `Time` is constructed in `uuid`
-rw-r--r--core/encoding/uuid/reading.odin8
-rw-r--r--tests/core/encoding/uuid/test_core_uuid.odin48
2 files changed, 27 insertions, 29 deletions
diff --git a/core/encoding/uuid/reading.odin b/core/encoding/uuid/reading.odin
index d41606f63..ab08300b0 100644
--- a/core/encoding/uuid/reading.odin
+++ b/core/encoding/uuid/reading.odin
@@ -163,8 +163,7 @@ Returns:
- timestamp: The timestamp of the UUID.
*/
time_v1 :: proc "contextless" (id: Identifier) -> (timestamp: time.Time) {
- delta := cast(time.Duration)(raw_time_v1(id) - HNS_INTERVALS_BETWEEN_GREG_AND_UNIX) * 100
- return time.time_add({}, delta)
+ return { _nsec = cast(i64)(raw_time_v1(id) - HNS_INTERVALS_BETWEEN_GREG_AND_UNIX) * 100 }
}
/*
@@ -195,8 +194,7 @@ Returns:
- timestamp: The timestamp, in 100-nanosecond intervals since 1582-10-15.
*/
time_v6 :: proc "contextless" (id: Identifier) -> (timestamp: time.Time) {
- delta := cast(time.Duration)(raw_time_v6(id) - HNS_INTERVALS_BETWEEN_GREG_AND_UNIX) * 100
- return time.time_add({}, delta)
+ return { _nsec = cast(i64)(raw_time_v6(id) - HNS_INTERVALS_BETWEEN_GREG_AND_UNIX) * 100 }
}
/*
@@ -223,7 +221,7 @@ Returns:
- timestamp: The timestamp, in milliseconds since the UNIX epoch.
*/
time_v7 :: proc "contextless" (id: Identifier) -> (timestamp: time.Time) {
- return time.time_add({}, cast(time.Duration)(raw_time_v7(id) * 1e6))
+ return { _nsec = cast(i64)raw_time_v7(id) * 1e6 }
}
/*
diff --git a/tests/core/encoding/uuid/test_core_uuid.odin b/tests/core/encoding/uuid/test_core_uuid.odin
index 9f66b316d..619534a7f 100644
--- a/tests/core/encoding/uuid/test_core_uuid.odin
+++ b/tests/core/encoding/uuid/test_core_uuid.odin
@@ -144,9 +144,9 @@ test_legacy_namespaced_uuids :: proc(t: ^testing.T) {
test_v1 :: proc(t: ^testing.T) {
context.random_generator = crypto.random_generator()
- point_a := time.time_add({}, 1 * time.Second)
- point_b := time.time_add({}, 3 * time.Second)
- point_c := time.time_add({}, 5 * time.Second)
+ point_a := time.unix(1, 0)
+ point_b := time.unix(3, 0)
+ point_c := time.unix(5, 0)
CLOCK :: 0x3A1A
mac := [6]u8{0xFF, 0x10, 0xAA, 0x55, 0x01, 0xFF}
@@ -179,9 +179,9 @@ test_v1 :: proc(t: ^testing.T) {
test_v6 :: proc(t: ^testing.T) {
context.random_generator = crypto.random_generator()
- point_a := time.time_add({}, 1 * time.Second)
- point_b := time.time_add({}, 3 * time.Second)
- point_c := time.time_add({}, 5 * time.Second)
+ point_a := time.unix(1, 0)
+ point_b := time.unix(3, 0)
+ point_c := time.unix(5, 0)
CLOCK :: 0x3A1A
mac := [6]u8{0xFF, 0x10, 0xAA, 0x55, 0x01, 0xFF}
@@ -214,9 +214,9 @@ test_v6 :: proc(t: ^testing.T) {
test_v7 :: proc(t: ^testing.T) {
context.random_generator = crypto.random_generator()
- point_a := time.time_add({}, 1 * time.Second)
- point_b := time.time_add({}, 3 * time.Second)
- point_c := time.time_add({}, 5 * time.Second)
+ point_a := time.unix(1, 0)
+ point_b := time.unix(3, 0)
+ point_c := time.unix(5, 0)
v7_a := uuid.generate_v7(point_a)
v7_b := uuid.generate_v7(point_b)
@@ -245,11 +245,11 @@ test_sorting_v1 :: proc(t: ^testing.T) {
// They are incapable of sorting properly by the nature their time bit ordering.
//
// Something is very strange if they do sort correctly.
- point_a := time.time_add({}, 1 * time.Second)
- point_b := time.time_add({}, 3 * time.Second)
- point_c := time.time_add({}, 5 * time.Second)
- point_d := time.time_add({}, 7 * time.Second)
- point_e := time.time_add({}, 11 * time.Second)
+ point_a := time.unix(1, 0)
+ point_b := time.unix(3, 0)
+ point_c := time.unix(5, 0)
+ point_d := time.unix(7, 0)
+ point_e := time.unix(11, 0)
mac: [6]byte
v1_a := uuid.generate_v1(0, mac, point_a)
@@ -283,11 +283,11 @@ test_sorting_v1 :: proc(t: ^testing.T) {
test_sorting_v6 :: proc(t: ^testing.T) {
context.random_generator = crypto.random_generator()
- point_a := time.time_add({}, 1 * time.Second)
- point_b := time.time_add({}, 3 * time.Second)
- point_c := time.time_add({}, 5 * time.Second)
- point_d := time.time_add({}, 7 * time.Second)
- point_e := time.time_add({}, 11 * time.Second)
+ point_a := time.unix(1, 0)
+ point_b := time.unix(3, 0)
+ point_c := time.unix(5, 0)
+ point_d := time.unix(7, 0)
+ point_e := time.unix(11, 0)
mac: [6]byte
v6_a := uuid.generate_v6(0, mac, point_a)
@@ -326,11 +326,11 @@ test_sorting_v6 :: proc(t: ^testing.T) {
test_sorting_v7 :: proc(t: ^testing.T) {
context.random_generator = crypto.random_generator()
- point_a := time.time_add({}, 1 * time.Second)
- point_b := time.time_add({}, 3 * time.Second)
- point_c := time.time_add({}, 5 * time.Second)
- point_d := time.time_add({}, 7 * time.Second)
- point_e := time.time_add({}, 11 * time.Second)
+ point_a := time.unix(1, 0)
+ point_b := time.unix(3, 0)
+ point_c := time.unix(5, 0)
+ point_d := time.unix(7, 0)
+ point_e := time.unix(11, 0)
v7_a := uuid.generate_v7(point_a)
v7_b := uuid.generate_v7(point_b)