| 49 | } |
| 50 | |
| 51 | func getTime(customTime *time.Time) (Time, uint16, error) { |
| 52 | var t time.Time |
| 53 | if customTime == nil { // When not provided, use the current time |
| 54 | t = timeNow() |
| 55 | } else { |
| 56 | t = *customTime |
| 57 | } |
| 58 | |
| 59 | // If we don't have a clock sequence already, set one. |
| 60 | if clockSeq == 0 { |
| 61 | setClockSequence(-1) |
| 62 | } |
| 63 | now := uint64(t.UnixNano()/100) + g1582ns100 |
| 64 | |
| 65 | // If time has gone backwards with this clock sequence then we |
| 66 | // increment the clock sequence |
| 67 | if now <= lasttime { |
| 68 | clockSeq = ((clockSeq + 1) & 0x3fff) | 0x8000 |
| 69 | } |
| 70 | lasttime = now |
| 71 | return Time(now), clockSeq, nil |
| 72 | } |
| 73 | |
| 74 | // ClockSequence returns the current clock sequence, generating one if not |
| 75 | // already set. The clock sequence is only used for Version 1 UUIDs. |