Datetime to fixed hash. Shortable for lower precision
Project description
HashDate
Turns Python datetimes (or iso dates with cli
) into hashes.
The hashes support shortening to reduce precision, so a prefix of a hash will be the same datetime rounded to the given hashlength.
Cli usage
Check out the demo:
$ hashdate demo
Its full of colors:
Turn your iso date into a hash:
$ hashdate date2hash 2020-05-13T22:30:47.136450
hash: UCABCBDCCDAEHBDGEFA
Then if you only take the first 11 chars you get a datetime with less precision:
$ hashdate hash2date UCABCBDCCDA
datetime: 2020-05-13T22:30:00
you can also secify to use emojis for charset if you want to:
$ hashdate date2hash 2020-05-13T22:30:47.136450 -c emoji
hash: ๐น๐ฒ๐ผ๐ฅ๐ฒ๐ฅ๐ฒ๐ฒ๐ฒ๐ฒ๐ผ๐๐๐ฅ๐ฒ๐ด๐๐๐ผ
and back again:
$ hash2date ๐น๐ฒ๐ผ๐ฅ๐ฒ๐ฅ๐ฒ๐ฒ๐ฒ๐ฒ๐ผ๐๐๐ฅ๐ฒ๐ด๐๐๐ผ -c emoji
datetime: 2020-05-13T22:30:47.136450
Module usage
import datetime
from hashdate import datetime_to_hash, hash_to_datetime
now = datetime.datetime.now()
hash = datetime_to_hash(now)
dt = hash_to_datetime(hash)
assert now == dt
Advanced
Use emojis:
import datetime
from hashdate import datetime_to_hash, hash_to_datetime
now = datetime.datetime.now()
hash = datetime_to_hash(now, charset='emoji')
dt = hash_to_datetime(hash, charset='emoji')
assert now == dt
Register more charsets:
import datetime
from hashdate import register_charset, datetime_to_hash, hash_to_datetime
charset = "๐ผ๐ฅ๐ฒ๐ฒ๐๐๐ด๐๐๐บ๐๐ฝ๐๐ฆ๐๐ฑ๐ซ๐๐๐๐น๐โ๐ฟ๐ฅ๐ช๐ท๐ต๐ฅ๐ท๐ณ๐ถ๐ฅ๐๐๐๐ต๐ป๐ฝ๐ข๐๐๐ฎ๐๐๐ฅ๐ฐ๐๐๐ง๐๐๐ฎ๐ธ๐๐๐๐๐ฅ๐๐ฅ๐ญ๐ธ๐"
register_charset('my_emojis', charset)
now = datetime.datetime.now()
hash = datetime_to_hash(now, charset='my_emojis')
dt = hash_to_datetime(hash, charset='my_emojis')
assert now == dt
Structure of a hashdate
centenial: [...19,20,21...]
| quarter start month: [0,3,6,9]
| | day in tens: [0:3]
| | | hour in tens: [0:5]
| | | | minute in tens: [0:5]
| | | | | second in tens: [0:5]
| | | | | | microsecond digits:[0:999999]
| | | | | | |
U CA B C B D C B A F C E BCDAAB
| | | | | |
| | | | | second: [0:9]
| | | | minute: [0:9]
| | | hour: [0:9]
| | day: [0:9]
| month in quarter: [0,1,2]
year: [0:99]
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
hashdate-1.0.3.tar.gz
(6.7 kB
view hashes)