Forráskód Böngészése

proper decoding of nanoseconds in TimeUUID

Zach Marcantel 11 éve
szülő
commit
3a2a2a96a1
2 módosított fájl, 4 hozzáadás és 4 törlés
  1. 1 1
      uuid.go
  2. 3 3
      uuid_test.go

+ 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())
 	}
 }