-
Notifications
You must be signed in to change notification settings - Fork 588
/
Copy pathtimestruct_linux_test.go
42 lines (36 loc) · 1.16 KB
/
timestruct_linux_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2024 The Go Authors. All right reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build linux
package unix_test
import (
"testing"
"time"
"golang.org/x/sys/unix"
)
func TestTimeToPtpClockTime(t *testing.T) {
testcases := []struct {
time time.Time
}{
{time.Unix(0, 0)},
{time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)},
{time.Date(2262, time.December, 31, 23, 0, 0, 0, time.UTC)},
{time.Unix(0x7FFFFFFF, 0)},
{time.Unix(0x80000000, 0)},
{time.Unix(0x7FFFFFFF, 1000000000)},
{time.Unix(0x7FFFFFFF, 999999999)},
{time.Unix(-0x80000000, 0)},
{time.Unix(-0x80000001, 0)},
{time.Date(2038, time.January, 19, 3, 14, 7, 0, time.UTC)},
{time.Date(2038, time.January, 19, 3, 14, 8, 0, time.UTC)},
{time.Date(1901, time.December, 13, 20, 45, 52, 0, time.UTC)},
{time.Date(1901, time.December, 13, 20, 45, 51, 0, time.UTC)},
}
for _, tc := range testcases {
ts := unix.TimeToPtpClockTime(tc.time)
tstime := time.Unix(int64(ts.Sec), int64(ts.Nsec))
if !tstime.Equal(tc.time) {
t.Errorf("TimeToPtpClockTime(%v) is the time %v", tc.time, tstime)
}
}
}