Skip to main content

Datetime to fixed hash. Shortable for lower precision

Project description

hashdate

HashDate

Latest Version License: MIT

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:

asciicast

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 details)

Uploaded Source

Built Distribution

hashdate-1.0.3-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file hashdate-1.0.3.tar.gz.

File metadata

  • Download URL: hashdate-1.0.3.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.7.3 Darwin/19.0.0

File hashes

Hashes for hashdate-1.0.3.tar.gz
Algorithm Hash digest
SHA256 a6884148b905f2b6b09706d47d17db1bd6b1609dd909b2e9da21107841ad6158
MD5 c6d695c74c0db74b1c1c3bd694b889b9
BLAKE2b-256 ca2548a7439c035e74b28eb859943d2d1c508670f4dad1bbca5eb09b7391a9c5

See more details on using hashes here.

File details

Details for the file hashdate-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: hashdate-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.7.3 Darwin/19.0.0

File hashes

Hashes for hashdate-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5f786cebf908bc4adf4296050bff249e35821dd2390f109d14bbf389e576bc01
MD5 81e98c6f3e18fd2998710aea730ecde3
BLAKE2b-256 4a1b6bd9a36df4d4ec7df6ecf80722018e3eb2afa6ac5f38c7db288eec63c068

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page