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 getSecondsFromTimecode(cls, timecode, zeroTime =None): if zeroTime is None: zeroTime = cls._ZERO_TIME if timecode is None: return zeroTime return 60*(Base64.from64(timecode)) + zeroTime
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 timecodeToDatetime(cls, timeCode, baseTime=0): """ Returns the datetime object that represents the given Base64 timeCode for the given base time, which by default is 0. """ return cls.secondsToDatetime(Base64.from64(timeCode) + baseTime)
def getPrefix(self): return Base64.to64(TimeUtils.getNowSeconds() - self._zeroTime)
def to64(cls, value): """Doc...""" return Base64.to64(int(value))
def i64(self): return Base64.to64(self.i)
def from64(cls, value): """Doc...""" return Base64.from64(value, True)
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 timecodeToDatetime(cls, timeCode, baseTime =0): """ Returns the datetime object that represents the given Base64 timeCode for the given base time, which by default is 0. """ return cls.secondsToDatetime(Base64.from64(timeCode) + baseTime)
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 _parseTimestamp(cls, value): if value is None: return datetime.datetime.utcnow() elif StringUtils.isStringType(value): return TimeUtils.secondsToDatetime(Base64.from64(value) + PyGlassEnvironment.BASE_UNIX_TIME) return value
def getNowTimecode(cls, baseTime =0): return Base64.to64(cls.getNowSeconds() - baseTime)
def getCurrentID(cls, sep ='::'): return str(os.getpid()) + '-' + Base64.to64(threading.current_thread().ident) \ + sep + str(threading.current_thread().name)