datetime from uuid1 timestamp

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kent Tenney

    datetime from uuid1 timestamp

    Howdy,

    I have not found a routine to extract usable
    date/time information from the 60 bit uuid1 timestamp.

    Is there not a standard solution?

    Thanks,
    Kent

  • gordyt

    #2
    Re: datetime from uuid1 timestamp

    Howdy Kent,

    Interesting question! Give this a shot:

    import datetime
    import time
    import uuid

    # get offset in seconds between the UUID timestamp Epoch (1582-10-15)
    and
    # the Epoch used on this computer
    DTD_SECS_DELTA = (datetime.datet ime(*time.gmtim e(0)[0:3])-
    datetime.dateti me(1582, 10, 15)).days * 86400
    def uuid1_to_ts(u):
    """Return a datetime.dateti me object that represents the timestamp
    portion of a uuid1.

    Parameters:
    u -- a type 1 uuid.UUID value

    Example usage:

    print uuid1_to_ts(uui d.uuid1())
    """
    secs_uuid1 = u.time / 1e7
    secs_epoch = secs_uuid1 - DTD_SECS_DELTA
    return datetime.dateti me.fromtimestam p(secs_epoch)


    --gordon

    Comment

    Working...