1 unstable release
0.1.0 | Dec 10, 2024 |
---|
#241 in Date and time
139 downloads per month
13KB
159 lines
ts32: timestamp in base 32
Developers mostly settled with RFC 3339 or ISO 8601 for textual timestamps. They are clean and concise, but sometimes we want even shorter representations. Introducing ts32:
- Advantages: much shorter than RFC 3339 while still being (relatively) human friendly and sortable
- Disadvantages: hard to parse exact values in untrained eyes
[(https://img.shields.io/crates/v/ts32?style=flat-square&logo=rust)] [(https://img.shields.io/docsrs/ts32?style=flat-square)]
This repository includes the "canonical" implementation written in Rust.
.... part encoding range
YMD.HSss[.i] Y base32(3-digit segments of year decimal)[] [00, z7][] M base32(month) [1, c] D base32(day) [1, z] : date:time separator H base32(hour) [0, q] S base32(sixth of hour) [0, 5] ss base32(seconds in sixth of hour) [00, jq] . millisecond separator i base32(millisecond) [00, z7] ....
- The alphabet is Crockford, i.e. excluding letters ILOU
- Encodings are big endian, e.g.
12
==1 << 5 2
Y
omits leading zero(es)
For a typical instant in the second millennium:
.... 3339 = 2024-12-31T01:23:45.233 ts32 = 20rcz:1271.79 20r - year 2024 2 - [2]024, leading zero omitted (full 02) 0r - 2[024] c - month 12 z - day 31 : - date:time separator 1 - hour 1 2 - 2nd sixth (0-based) of hour, i.e. 20:00-29:59 71 - seconds in sixth of hour 225 = 3:45 . - millisecond separator 79 - milliseconds 233
len(3339) = 23 len(ts32) = 13 len(u64) = 8 ....
- Byte savings compared to RFC 3339 are (23 - 13)/23 = 43.5%
- Overhead compared to u64 timestamp is (13 - 8)/8 = 62.5% (RFC 3339 is 187.5%)
Dependencies
~0.3–1.2MB
~25K SLoC