Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion model/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (t Time) Time() time.Time {
// Unix returns t as a Unix time, the number of seconds elapsed
// since January 1, 1970 UTC.
func (t Time) Unix() int64 {
return int64(t) / second
return t.Time().Unix()
}

// UnixNano returns t as a Unix time, the number of nanoseconds elapsed
Expand Down
24 changes: 24 additions & 0 deletions model/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,30 @@ func TestTimeConversions(t *testing.T) {
require.Equalf(t, ts.UnixNano(), unixNano-unixNano%nanosPerTick, "Expected %d, got %d", unixNano, ts.UnixNano())
}

func TestTimeUnix(t *testing.T) {
for _, tc := range []struct {
milliseconds Time
seconds int64
}{
{Earliest, -9223372036854776},
{-1001, -2},
{-1000, -1},
{-999, -1},
{-1, -1},
{0, 0},
{1, 0},
{999, 0},
{1000, 1},
{1001, 1},
{Latest, 9223372036854775},
} {
t.Run(strconv.FormatInt(int64(tc.milliseconds), 10), func(t *testing.T) {
require.Equal(t, tc.seconds, tc.milliseconds.Unix())
require.Equal(t, tc.milliseconds.Time().Unix(), tc.milliseconds.Unix())
})
}
}

func TestDuration(t *testing.T) {
duration := time.Second + time.Minute + time.Hour
goTime := time.Unix(1136239445, 0)
Expand Down
Loading