From 5fef757904059bd0b855bc57ba31851ead349ac8 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 7 Apr 2025 18:17:34 -0400 Subject: Fix uuids --- Makefile | 2 +- lib/uuid/uuid.tm | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index fbd2d0f7..ad56a549 100644 --- a/Makefile +++ b/Makefile @@ -137,7 +137,7 @@ install: build/tomo build/$(LIB_FILE) rm -f "$(PREFIX)/bin/tomo" cp -v build/tomo "$(PREFIX)/bin/" cp -v docs/tomo.1 "$(PREFIX)/man/man1/" - ./build/tomo -qIL lib/patterns lib/time lib/commands lib/shell lib/random lib/base64 lib/pthreads lib/core + ./build/tomo -qIL lib/patterns lib/time lib/commands lib/shell lib/random lib/base64 lib/pthreads lib/uuid lib/core uninstall: rm -rvf "$(PREFIX)/bin/tomo" "$(PREFIX)/include/tomo" "$(PREFIX)/lib/$(LIB_FILE) "$(PREFIX)/share/tomo"; \ diff --git a/lib/uuid/uuid.tm b/lib/uuid/uuid.tm index 002b4808..06d48390 100644 --- a/lib/uuid/uuid.tm +++ b/lib/uuid/uuid.tm @@ -1,3 +1,6 @@ +use random +use time + lang UUID func v4(-> UUID) # Random UUID bytes := &random.bytes(16) @@ -8,8 +11,8 @@ lang UUID return UUID.from_text(uuid) func v7(-> UUID) # Timestamp + random UUID - n := now() - timestamp := n.seconds*1000 + n.microseconds/1_000 + n := Time.now() + timestamp := n.tv_sec*1000 + n.tv_usec/1_000 bytes := [ Byte((timestamp >> 40)), @@ -31,6 +34,6 @@ lang UUID enum UUIDVersion(v4, v7) func main(version=UUIDVersion.v7) when version is v4 - say(UUID.v4().text_content) + say(UUID.v4().text) is v7 - say(UUID.v7().text_content) + say(UUID.v7().text) -- cgit v1.2.3