2021-04-25 21:53:17 +03:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUser_TZ(t *testing.T) {
|
|
|
|
sut1, sut2 := &User{Location: ""}, &User{Location: "America/Los_Angeles"}
|
|
|
|
pst, _ := time.LoadLocation("America/Los_Angeles")
|
2021-11-28 14:40:46 +03:00
|
|
|
_, offset1 := time.Now().Zone()
|
|
|
|
_, offset2 := time.Now().In(pst).Zone()
|
2021-04-25 21:53:17 +03:00
|
|
|
|
|
|
|
assert.Equal(t, time.Local, sut1.TZ())
|
|
|
|
assert.Equal(t, pst, sut2.TZ())
|
|
|
|
|
2021-11-28 14:40:46 +03:00
|
|
|
assert.InDelta(t, time.Duration(offset1*int(time.Second)), sut1.TZOffset(), float64(1*time.Second))
|
|
|
|
assert.InDelta(t, time.Duration(offset2*int(time.Second)), sut2.TZOffset(), float64(1*time.Second))
|
2021-04-25 21:53:17 +03:00
|
|
|
}
|