diff --git a/lib/Bastion/Chronology.py b/lib/Bastion/Chronology.py index bac9cd2..9ecd72d 100644 --- a/lib/Bastion/Chronology.py +++ b/lib/Bastion/Chronology.py @@ -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). @@ -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