photoprism/pkg/time/tz/utc_test.go
Michael Mayer f2a89063c6 Metadata: Fix typo in LocationUTC() function #4622 #4946
Signed-off-by: Michael Mayer <michael@photoprism.app>
2025-04-23 17:54:33 +02:00

57 lines
1.2 KiB
Go

package tz
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestIsUTC(t *testing.T) {
t.Run("True", func(t *testing.T) {
assert.True(t, IsUTC("utc"))
assert.True(t, IsUTC("UTC"))
assert.True(t, IsUTC("Z"))
assert.True(t, IsUTC("Zulu"))
})
t.Run("False", func(t *testing.T) {
assert.False(t, IsUTC(""))
assert.False(t, IsUTC("GMT"))
assert.False(t, IsUTC("local"))
assert.False(t, IsUTC("Local"))
})
}
func TestTruncateUTC(t *testing.T) {
now := time.Now().In(TimeLocal)
ns := now.Nanosecond()
result := TruncateUTC(now)
assert.Equal(t, TimeUTC, result.Location())
timeZone, _ := result.Zone()
assert.Equal(t, UTC, timeZone)
assert.Equal(t, 0, result.Nanosecond())
if ns > 0 {
assert.NotEqual(t, ns, result.Nanosecond())
}
}
func TestLocationUTC(t *testing.T) {
loc := Find("Europe/Berlin")
now := time.Now().In(loc).UTC()
ns := now.Nanosecond()
t.Logf("now: %s", now.String())
result := LocationUTC(now, loc)
t.Logf("result: %s", result.String())
assert.Equal(t, TimeUTC, result.Location())
timeZone, _ := result.Zone()
assert.Equal(t, UTC, timeZone)
assert.Equal(t, 0, result.Nanosecond())
if ns > 0 {
assert.NotEqual(t, ns, result.Nanosecond())
}
}