Time returns the time in 100s of nanoseconds since 15 Oct 1582 encoded in uuid. The time is only defined for version 1, 2, 6 and 7 UUIDs.
()
| 115 | // Time returns the time in 100s of nanoseconds since 15 Oct 1582 encoded in |
| 116 | // uuid. The time is only defined for version 1, 2, 6 and 7 UUIDs. |
| 117 | func (uuid UUID) Time() Time { |
| 118 | var t Time |
| 119 | switch uuid.Version() { |
| 120 | case 6: |
| 121 | time := int64(binary.BigEndian.Uint32(uuid[0:4])) << 28 |
| 122 | time |= int64(binary.BigEndian.Uint16(uuid[4:6])) << 12 |
| 123 | time |= int64(binary.BigEndian.Uint16(uuid[6:8]) & 0xfff) |
| 124 | t = Time(time) |
| 125 | case 7: |
| 126 | time := binary.BigEndian.Uint64(uuid[:8]) |
| 127 | t = Time((time>>16)*10000 + g1582ns100) |
| 128 | default: // forward compatible |
| 129 | time := int64(binary.BigEndian.Uint32(uuid[0:4])) |
| 130 | time |= int64(binary.BigEndian.Uint16(uuid[4:6])) << 32 |
| 131 | time |= int64(binary.BigEndian.Uint16(uuid[6:8])&0xfff) << 48 |
| 132 | t = Time(time) |
| 133 | } |
| 134 | return t |
| 135 | } |
| 136 | |
| 137 | // ClockSequence returns the clock sequence encoded in uuid. |
| 138 | // The clock sequence is only well defined for version 1 and 2 UUIDs. |