Skip to content

Commit d344c6a

Browse files
committed
test: add test (based on #195 (comment) )
1 parent 3c2c7a6 commit d344c6a

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

uuid_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,56 @@ func TestTimestampFromV7(t *testing.T) {
281281
}
282282
}
283283

284+
func TestTimestampMinMaxV167(t *testing.T) {
285+
tests := []struct {
286+
u UUID
287+
want time.Time
288+
}{
289+
290+
// v1 min and max
291+
{u: Must(FromString("00000000-0000-1000-8000-000000000000")), want: time.Date(1582, 10, 15, 0, 0, 0, 0, time.UTC)}, //1582-10-15 0:00:00 (UTC)
292+
{u: Must(FromString("ffffffff-ffff-1fff-bfff-ffffffffffff")), want: time.Date(5236, 3, 31, 21, 21, 00, 684697500, time.UTC)}, //5236-03-31 21:21:00 (UTC)
293+
294+
// v6 min and max
295+
{u: Must(FromString("00000000-0000-6000-8000-000000000000")), want: time.Date(1582, 10, 15, 0, 0, 0, 0, time.UTC)}, //1582-10-15 0:00:00 (UTC)
296+
{u: Must(FromString("ffffffff-ffff-6fff-bfff-ffffffffffff")), want: time.Date(5236, 3, 31, 21, 21, 00, 684697500, time.UTC)}, //5236-03-31 21:21:00 (UTC)
297+
298+
// v7 min and max
299+
{u: Must(FromString("00000000-0000-7000-8000-000000000000")), want: time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC)}, //1970-01-01 0:00:00 (UTC)
300+
{u: Must(FromString("ffffffff-ffff-7fff-bfff-ffffffffffff")), want: time.Date(10889, 8, 2, 5, 31, 50, 655000000, time.UTC)}, //10889-08-02 5:31:50.655 (UTC)
301+
}
302+
for _, tt := range tests {
303+
var got Timestamp
304+
var err error
305+
var functionName string
306+
307+
switch tt.u.Version() {
308+
case V1:
309+
functionName = "TimestampFromV1"
310+
got, err = TimestampFromV1(tt.u)
311+
case V6:
312+
functionName = "TimestampFromV6"
313+
got, err = TimestampFromV6(tt.u)
314+
case V7:
315+
functionName = "TimestampFromV7"
316+
got, err = TimestampFromV7(tt.u)
317+
}
318+
319+
if err != nil {
320+
t.Errorf(functionName+"(%v) got error %v, want %v", tt.u, err, tt.want)
321+
}
322+
323+
tm, err := got.Time()
324+
if err != nil {
325+
t.Errorf(functionName+"(%v) got error %v, want %v", tt.u, err, tt.want)
326+
}
327+
328+
if !tt.want.Equal(tm) {
329+
t.Errorf(functionName+"(%v) got %v, want %v", tt.u, tm.UTC(), tt.want)
330+
}
331+
}
332+
}
333+
284334
func BenchmarkFormat(b *testing.B) {
285335
var tests = []string{
286336
"%s",

0 commit comments

Comments
 (0)