https://github.com/go-compile/tinytime
Tiny timestamps which can save 4x space compared to unix timestamps, without decreasing longevity.
https://github.com/go-compile/tinytime
bytes hours jwt seconds small stamp time timestamp tiny unix
Last synced: 7 months ago
JSON representation
Tiny timestamps which can save 4x space compared to unix timestamps, without decreasing longevity.
- Host: GitHub
- URL: https://github.com/go-compile/tinytime
- Owner: go-compile
- License: mit
- Created: 2023-01-02T18:35:21.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-01-02T18:39:23.000Z (about 3 years ago)
- Last Synced: 2025-07-22T00:33:57.407Z (8 months ago)
- Topics: bytes, hours, jwt, seconds, small, stamp, time, timestamp, tiny, unix
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TinyTime
_`Tiny Timestamps That Last Forever.`_
TinyTime lets you choose how precise you want your timestamp to be, enabling shorter TinyTime stamps to be used when length/size is a concern. With TinyTime you can use a 32bit integer timestamp saving 50% of length compared to standard Unix timestamp. This can be achieved through storing **minutes rather than seconds**, or hours instead of minutes, days instead of hours etc. Even though the timestamps are smaller they will still last for thousands of years, something a Unix timestamp will not in a 32bit integer.
## The Problem This Solves
Communicating a unix timestamp in readable ASCII requires **16 bytes** (in HEX), something which can make stateless tokens, urls or other usages too large, bloating and wasting characters. With TinyTime that same time stamp can be reduced to only **4 bytes** by storing the hour. In most cases down to the second precision is unnecessary. For example, a user token expiration; we only need to know at `X` hour it expires, the exact second is unimportant.
When storing TinyTime as bytes the smallest timestamp can be `2 bytes` or `3 bytes` if stored as base64.
## Install Now
*Theres no TinyTime like the present.*
```sh
go get github.com/go-compile/tinytime
```
## Example
More examples can be found in [the examples folder](./examples/).
```go
package main
import (
"encoding/hex"
"fmt"
"github.com/go-compile/tinytime"
)
func main() {
d := tinytime.Now().Days()
// store in as small format as possible as HEX
fmt.Println("Smallest Possible:", tinytime.ToBytes(d))
fmt.Println("Smallest Possible (Hex):", hex.EncodeToString(tinytime.ToBytes(d)))
}
```