Skip to content
Merged
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
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)
}
})
}
}