Crates.io | pubky-timestamp |
lib.rs | pubky-timestamp |
version | 0.2.0 |
source | src |
created_at | 2024-10-17 14:03:27.204748 |
updated_at | 2024-10-17 14:40:31.082381 |
description | Strictly monotonic unix timestamp in microseconds |
homepage | |
repository | https://github.com/pubky/timestamp |
max_upload_size | |
id | 1413253 |
size | 17,203 |
Strictly monotonic unix timestamp in microseconds.
Unlike calling [SystemTime::now], calling [Timestamp::now] is guaranteed to always create an increasing timestamp, never moving back in time, nor repeating the same timestamp even if you call it many timest within the same microsecond.
Always encoded as Big-endian u64, so that it can be used as sortable keys.
If you enable base32
feature, you can also get sortable utf-8 representation of 13 characters, that are also easy to copy visually.
for example 0032992ANQB5G
.
If you enable httpdate
you can format [Timestamp] as http date format, or parse an http date to a timestamp.
While it can't be used as a globally unique Id, it is unique within the same process.
If you use it concurrently through different processes, each process will create a unique one-byte clock_id
.
This means that if you setup your custom [TimestampFactory], you can have up to 256
processes all generating unique timestamps.
Otherwise, if you use the [DEFAULT_FACTORY], which sets the [TimestampFactory::clock_id] randomly, your chance of having unique clock ids is relative to how many processes are you running, and how often do you restart these processes.