def getUidTimecode(cls, prefix=None, suffix=None): """ Creates a timecode down to the microsecond for use in creating unique UIDs. """ out = Base64.to64(cls.getNowSeconds()) + '-' + Base64.to64( datetime.microsecond) return ((StringUtils.toUnicode(prefix) + '-') if prefix else '') + out \ + (('-' + StringUtils.toUnicode(suffix)) if suffix else '')
def getUidTimecode(cls, prefix=None, suffix=None): """ Creates a timecode down to the microsecond for use in creating unique UIDs. """ out = Base64.to64(cls.getNowSeconds()) + "-" + Base64.to64(datetime.microsecond) return ( ((StringUtils.toUnicode(prefix) + "-") if prefix else "") + out + (("-" + StringUtils.toUnicode(suffix)) if suffix else "") )
def createUniqueId(cls, prefix = u''): """ Creates a universally unique identifier string based on current time, active application instance state, and a randomized hash """ cls._UID_INDEX += 1 return '%s%s-%s-%s' % ( prefix, TimeUtils.getNowTimecode(cls.BASE_UNIX_TIME), Base64.to64(cls._UID_INDEX), StringUtils.getRandomString(12))
def getTimecodeFromDatetime(cls, time =None, zeroTime =None, rotationInterval =None): if zeroTime is None: zeroTime = cls._ZERO_TIME if rotationInterval is None: rotationInterval = cls._ROTATION_INTERVAL if time is None: time = datetime.datetime.utcnow() t = float(TimeUtils.datetimeToSeconds(time) - zeroTime)/60.0 t = float(rotationInterval)*math.floor(t/float(rotationInterval)) return Base64.to64(int(t))
def getCurrentID(cls, sep ='::'): return str(os.getpid()) + '-' + Base64.to64(threading.current_thread().ident) \ + sep + str(threading.current_thread().name)
def i64(self): return Base64.to64(self.i)
def getNowTimecode(cls, baseTime=0): return Base64.to64(cls.getNowSeconds() - baseTime)
def datetimeToTimecode(cls, dt, baseTime=0): """ Returns a timecode (base64 encoded seconds string) for the given datetime object and offset by the baseTime number of seconds. """ return Base64.to64(cls.datetimeToSeconds(dt) - baseTime)
def getPrefix(self): return Base64.to64(TimeUtils.getNowSeconds() - self._zeroTime)
def getNowTimecode(cls, baseTime =0): return Base64.to64(cls.getNowSeconds() - baseTime)
def datetimeToTimecode(cls, dt, baseTime =0): """ Returns a timecode (base64 encoded seconds string) for the given datetime object and offset by the baseTime number of seconds. """ return Base64.to64(cls.datetimeToSeconds(dt) - baseTime)
def to64(cls, value): """Doc...""" return Base64.to64(int(value))