Skip to content

Commit

Permalink
add time test
Browse files Browse the repository at this point in the history
  • Loading branch information
BK1031 committed Aug 30, 2024
1 parent 9fe3c95 commit ec52bb1
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions utils/time_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package utils

import (
"testing"
"time"
)

func TestWithPrecision(t *testing.T) {
tests := []struct {
name string
input time.Time
expected time.Time
}{
{
name: "Round to microsecond precision",
input: time.Date(2023, 4, 15, 12, 30, 45, 123456789, time.UTC),
expected: time.Date(2023, 4, 15, 12, 30, 45, 123457000, time.UTC),
},
{
name: "Already at microsecond precision",
input: time.Date(2023, 4, 15, 12, 30, 45, 123000000, time.UTC),
expected: time.Date(2023, 4, 15, 12, 30, 45, 123000000, time.UTC),
},
{
name: "Round up to next microsecond",
input: time.Date(2023, 4, 15, 12, 30, 45, 123999999, time.UTC),
expected: time.Date(2023, 4, 15, 12, 30, 45, 124000000, time.UTC),
},
{
name: "Round down to previous microsecond",
input: time.Date(2023, 4, 15, 12, 30, 45, 123000001, time.UTC),
expected: time.Date(2023, 4, 15, 12, 30, 45, 123000000, time.UTC),
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := WithPrecision(tt.input)
if !result.Equal(tt.expected) {
t.Errorf("WithPrecision(%v) = %v, want %v", tt.input, result, tt.expected)
}
})
}
}

0 comments on commit ec52bb1

Please sign in to comment.