Пример #1
0
    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 '')
Пример #2
0
    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 "")
        )
Пример #3
0
    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
Пример #4
0
    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
Пример #5
0
 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))
Пример #6
0
    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))
Пример #7
0
    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))
Пример #8
0
 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)
Пример #9
0
 def getPrefix(self):
     return Base64.to64(TimeUtils.getNowSeconds() - self._zeroTime)
Пример #10
0
 def to64(cls, value):
     """Doc..."""
     return Base64.to64(int(value))
Пример #11
0
 def i64(self):
     return Base64.to64(self.i)
Пример #12
0
 def to64(cls, value):
     """Doc..."""
     return Base64.to64(int(value))
Пример #13
0
 def from64(cls, value):
     """Doc..."""
     return Base64.from64(value, True)
Пример #14
0
 def getPrefix(self):
     return Base64.to64(TimeUtils.getNowSeconds() - self._zeroTime)
Пример #15
0
 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)
Пример #16
0
 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)
Пример #17
0
 def getNowTimecode(cls, baseTime=0):
     return Base64.to64(cls.getNowSeconds() - baseTime)
Пример #18
0
 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)
Пример #19
0
 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
Пример #20
0
 def getNowTimecode(cls, baseTime =0):
     return Base64.to64(cls.getNowSeconds() - baseTime)
Пример #21
0
 def getCurrentID(cls, sep ='::'):
     return str(os.getpid()) + '-' + Base64.to64(threading.current_thread().ident) \
         + sep + str(threading.current_thread().name)
Пример #22
0
 def from64(cls, value):
     """Doc..."""
     return Base64.from64(value, True)