def __init__(self, s = None, monot = None, realt = None, trust_realt = False): if s != None: parts = s.split('-', 1) self.realt = float(parts[0]) if len(parts) == 1: self.__initFromRealt() else: self.monot = float(parts[1]) return if monot == None and realt == None: if trust_realt: raise TypeError('MonoTime.__init__: realt could not be None when trust_realt is set') realt = clock_getdtime(CLOCK_REALTIME) self.monot = clock_getdtime(CLOCK_MONOTONIC) diff_flt = self.globals.realt_flt.apply(realt - self.monot) if self.globals.monot_max < self.monot: self.globals.monot_max = self.monot self.realt = self.monot + diff_flt return if monot != None: self.monot = monot if realt != None: self.realt = realt else: self.realt = monot + self.globals.realt_flt.lastval return self.realt = realt self.__initFromRealt(trust_realt)
def __init__(self, s=None, monot=None, realt=None, trust_realt=False): if s != None: parts = s.split('-', 1) self.realt = float(parts[0]) if len(parts) == 1: self.__initFromRealt() else: self.monot = float(parts[1]) return if monot == None and realt == None: if trust_realt: raise TypeError( 'MonoTime.__init__: realt could not be None when trust_realt is set' ) realt = clock_getdtime(CLOCK_REALTIME) self.monot = clock_getdtime(CLOCK_MONOTONIC) diff_flt = self.globals.realt_flt.apply(realt - self.monot) if self.globals.monot_max < self.monot: self.globals.monot_max = self.monot self.realt = self.monot + diff_flt return if monot != None: self.monot = monot if realt != None: self.realt = realt else: self.realt = monot + self.globals.realt_flt.lastval return self.realt = realt self.__initFromRealt(trust_realt)
def __initFromRealt(self, trust_realt=False): self.monot = self.realt - self.globals.realt_flt.lastval if not trust_realt and self.monot > self.globals.monot_max: monot_now = clock_getdtime(CLOCK_MONOTONIC) if monot_now > self.globals.monot_max: self.globals.monot_max = monot_now self.monot = self.globals.monot_max
def __initFromRealt(self, trust_realt = False): self.monot = self.realt - self.globals.realt_flt.lastval if not trust_realt and self.monot > self.globals.monot_max: monot_now = clock_getdtime(CLOCK_MONOTONIC) if monot_now > self.globals.monot_max: self.globals.monot_max = monot_now self.monot = self.globals.monot_max
def __init__(self): realt = clock_getdtime(CLOCK_REALTIME) self.monot_max = clock_getdtime(CLOCK_MONOTONIC) self.realt_flt = recfilter(0.99, realt - self.monot_max)
def offsetFromNow(self): now = clock_getdtime(CLOCK_MONOTONIC) return (now - self.monot)