浏览代码

Merge pull request #289 from zmarcantel/master

proper decoding of nanoseconds in TimeUUID
Ben Hood 11 年之前
父节点
当前提交
1911d109ae
共有 3 个文件被更改,包括 5 次插入4 次删除
  1. 1 0
      AUTHORS
  2. 1 1
      uuid.go
  3. 3 3
      uuid_test.go

+ 1 - 0
AUTHORS

@@ -38,3 +38,4 @@ Matthias Kadenbach <matthias.kadenbach@gmail.com>
 Dean Elbaz <elbaz.dean@gmail.com>
 Mike Berman <evencode@gmail.com>
 Dmitriy Fedorenko <c0va23@gmail.com>
+Zach Marcantel <zmarcantel@gmail.com>

+ 1 - 1
uuid.go

@@ -217,7 +217,7 @@ func (u UUID) Time() time.Time {
 	}
 	t := u.Timestamp()
 	sec := t / 1e7
-	nsec := t % 1e7
+	nsec := (t % 1e7) * 100
 	return time.Unix(sec+timeBase, nsec).UTC()
 }
 

+ 3 - 3
uuid_test.go

@@ -134,7 +134,7 @@ func TestRandomUUIDInvalidAPICalls(t *testing.T) {
 }
 
 func TestUUIDFromTime(t *testing.T) {
-	date := time.Date(1982, 5, 5, 12, 34, 56, 0, time.UTC)
+	date := time.Date(1982, 5, 5, 12, 34, 56, 400, time.UTC)
 	uuid := UUIDFromTime(date)
 
 	if uuid.Time() != date {
@@ -144,8 +144,8 @@ func TestUUIDFromTime(t *testing.T) {
 
 func TestParseUUID(t *testing.T) {
 	uuid, _ := ParseUUID("486f3a88-775b-11e3-ae07-d231feb1dc81")
-	if uuid.Time().Truncate(time.Second) != time.Date(2014, 1, 7, 5, 19, 29, 0, time.UTC) {
-		t.Errorf("Expected date of 1/7/2014 at 5:19:29, got %v", uuid.Time())
+	if uuid.Time() != time.Date(2014, 1, 7, 5, 19, 29, 222516000, time.UTC) {
+		t.Errorf("Expected date of 1/7/2014 at 5:19:29.222516, got %v", uuid.Time())
 	}
 }