1 // Copyright 2014 Google Inc. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
10 guuid "github.com/google/uuid"
13 // A Time represents a time as the number of 100's of nanoseconds since 15 Oct
15 type Time = guuid.Time
17 // GetTime returns the current Time (100s of nanoseconds since 15 Oct 1582) and
18 // clock sequence as well as adjusting the clock sequence as needed. An error
19 // is returned if the current time cannot be determined.
20 func GetTime() (Time, uint16, error) { return guuid.GetTime() }
22 // ClockSequence returns the current clock sequence, generating one if not
23 // already set. The clock sequence is only used for Version 1 UUIDs.
25 // The uuid package does not use global static storage for the clock sequence or
26 // the last time a UUID was generated. Unless SetClockSequence a new random
27 // clock sequence is generated the first time a clock sequence is requested by
28 // ClockSequence, GetTime, or NewUUID. (section 4.2.1.1) sequence is generated
30 func ClockSequence() int { return guuid.ClockSequence() }
32 // SetClockSeq sets the clock sequence to the lower 14 bits of seq. Setting to
33 // -1 causes a new sequence to be generated.
34 func SetClockSequence(seq int) { guuid.SetClockSequence(seq) }
36 // Time returns the time in 100s of nanoseconds since 15 Oct 1582 encoded in
37 // uuid. It returns false if uuid is not valid. The time is only well defined
38 // for version 1 and 2 UUIDs.
39 func (uuid UUID) Time() (Time, bool) {
43 time := int64(binary.BigEndian.Uint32(uuid[0:4]))
44 time |= int64(binary.BigEndian.Uint16(uuid[4:6])) << 32
45 time |= int64(binary.BigEndian.Uint16(uuid[6:8])&0xfff) << 48
46 return Time(time), true
49 // ClockSequence returns the clock sequence encoded in uuid. It returns false
50 // if uuid is not valid. The clock sequence is only well defined for version 1
52 func (uuid UUID) ClockSequence() (int, bool) {
56 return int(binary.BigEndian.Uint16(uuid[8:10])) & 0x3fff, true