This is small Python package which encode standard timestamp to shorted form by using alphabetic symbols.
Project description
Alphabetic Timestamp
This is small Python package which encode standard timestamp to shorted form by using alphabetic symbols.
Installation
pip install alphabetic_timestamp
Description
User can use two base for coding. It other words two different lists of symbols for encoding.
-
Base36
-
Base62
Example of coding
This example show coding of datetime 2020-01-01 20:20:20.002000. It means timestamp 1577906420.002.
Time Units | Base36 | Base62 |
---|---|---|
seconds | q3g0dw | 1IMJxy |
deciseconds | 78yg3uw | hdRlpu |
centiseconds | 20hkh2kw | 2MeBs6Q |
milliseconds | k4voqpsy | rMm2x6q |
Symbols of Base 36
import alphabetic_timestamp as ats
print(ats.base36.symbols)
>>> 0123456789abcdefghijklmnopqrstuvwxyz
Symbols of Base 62
import alphabetic_timestamp as ats
print(ats.base62.symbols)
>>> 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
Interface
import datetime
import alphabetic_timestamp as ats
dt = datetime.datetime.now()
ts = dt.timestamp()
ats.base36.now(time_unit=ats.TimeUnit.seconds)
ats.base36.from_datetime(dt, time_unit=ats.TimeUnit.seconds)
ats.base36.from_timestamp(ts, time_unit=ats.TimeUnit.seconds)
ats.base36.to_datetime("q67vhw", time_unit=ats.TimeUnit.seconds, time_zone=None)
ats.base36.to_timestamp("q67vhw", time_unit=ats.TimeUnit.seconds)
Note: The string "q67vhw" is only example of encoded timestamp.
Examples
Encode & Print
import alphabetic_timestamp as ats
print(ats.base36.now())
# Current DT: 2020-02-24 18:34:44.349162
>>> q67vhw
Encoded & Decode
import datetime
import alphabetic_timestamp as ats
# DATETIME -> ALPHABETIC_TIMESTAMP -> DATETIME
dt = datetime.datetime.now()
alphabetic_ts_36 = ats.base36.from_datetime(dt)
decoded_ts_36 = ats.base36.to_datetime(alphabetic_ts_36)
alphabetic_ts_62 = ats.base62.from_datetime(dt)
decoded_ts_62 = ats.base62.to_datetime(alphabetic_ts_62)
# TIMESTAMP -> ALPHABETIC_TIMESTAMP -> TIMESTAMP
ts = dt.timestamp()
alphabetic_ts_36 = ats.base36.from_timestamp(ts)
decoded_ts_36 = ats.base36.to_timestamp(alphabetic_ts_36)
alphabetic_ts_62 = ats.base62.from_timestamp(ts)
decoded_ts_62 = ats.base62.to_timestamp(alphabetic_ts_62)
Time units
import datetime
import alphabetic_timestamp as ats
dt = datetime.datetime.now()
# Set time unit for current timestamp
now36_ts = ats.base36.now() # default: ats.TimeUnit.seconds
now36_ts = ats.base36.now(time_unit=ats.TimeUnit.seconds)
# Set time unit for specific datetime and timestamp
alphabetic_ts_36 = ats.base36.from_datetime(dt, time_unit=ats.TimeUnit.seconds)
alphabetic_ts_36 = ats.base36.from_timestamp(dt.timestamp(), time_unit=ats.TimeUnit.seconds)
# Examples of available time units
now36_ts = ats.base36.now(time_unit=ats.TimeUnit.deciseconds)
now36_ts = ats.base36.now(time_unit=ats.TimeUnit.centiseconds)
now36_ts = ats.base36.now(time_unit=ats.TimeUnit.milliseconds)
Possible Issue
There is a possible issue caused by bug in standard datetime module.
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
Close
Hashes for alphabetic_timestamp-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bce4f0a5ee1ff0c96fdf8ab24e8e5b19010e1dd7058d47fe439310d00a410da |
|
MD5 | 7d286cb82cab941ff75de6a96bc53ec8 |
|
BLAKE2b-256 | b0d9523c4db322938db38493afb7569e2ce9699ef8fd9904d04bcd49af960a2a |