Skip to content

Commit

Permalink
Created simpler functions for generating version timestamps using gen…
Browse files Browse the repository at this point in the history
…eral Quantim idea; also in progress of changing Quantim spec to use month and day instead of day of year.
  • Loading branch information
ndenny committed Jun 24, 2024
1 parent 742e84f commit cdfd7cc
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions lib/Bastion/Chronology.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,37 @@
logger = logging.getLogger(__name__)


def quantim3(then = None, **kwargs):
marker = kwargs.get('separator', '')
QUANTIM = 86400.0 / (36**2)
when = then if (then is not None) else datetime.datetime.now()
ds = (when.hour * 3600) + (when.minute * 60) + when.second + (when.microsecond / 1000000)
dq = round( ds / QUANTIM )
lsq = dq % 36
msq = dq // 36
xmap = list(string.digits + string.ascii_uppercase)
y3 = "{:03d}".format(when.year - 2000)
doy = "{:03d}".format(when.timetuple().tm_yday)
qt = xmap[msq] + xmap[lsq]
return marker.join([y3, doy, qt])


def quiver(then = None):
QUANTIM = 86400.0 / (36**2)
when = then if (then is not None) else datetime.datetime.now()
ds = (when.hour * 3600) + (when.minute * 60) + when.second + (when.microsecond / 1000000)
dq = round( ds / QUANTIM )
lsq = dq % 36
msq = dq // 36
xmap = list(string.digits + string.ascii_uppercase)
qt = xmap[msq] + xmap[lsq]

y2 = "{:02d}".format(when.year - 2000)
mo = "{:X}".format(when.month)

return "{}{}{}{}".format(y2, mo, when.day, qt)


class Quantim:
"""
Quantized Time (Quantim).
Expand All @@ -29,8 +60,8 @@ def __init__(self, whence, separator = None):
adnl_seconds = (whence - year_starts).seconds

self.dY = whence.year - 2000
self.dD = (whence - year_starts).days
self.qM = int(adnl_seconds // Quantim.QUANTUM)
self.dD = whence.timetuple().tm_yday
self.qM = round((whence.hour * 3600) + (whence.minute * 60) + whence.second + (whence.microsecond / 1000000)) // Quantim.QUANTUM

elif isinstance(whence, Quantim):
self.dY = whence.dY
Expand Down

0 comments on commit cdfd7cc

Please sign in to comment.