github.com/ydb-platform/ydb-go-sdk/v3@v3.89.2/internal/value/time_test.go (about) 1 package value 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestTzSomeToTime(t *testing.T) { 11 for _, tt := range []struct { 12 name string 13 src string 14 exp time.Time 15 converter func(string) (time.Time, error) 16 }{ 17 { 18 "TzDateToTime", 19 "2020-05-29,Europe/Berlin", 20 time.Date(2020, time.May, 29, 0, 0, 0, 0, 21 func() *time.Location { 22 l, _ := time.LoadLocation("Europe/Berlin") 23 24 return l 25 }(), 26 ), 27 TzDateToTime, 28 }, 29 { 30 "TzDatetimeToTime", 31 "2020-05-29T11:22:54,Europe/Berlin", 32 time.Date(2020, time.May, 29, 11, 22, 54, 0, 33 func() *time.Location { 34 l, _ := time.LoadLocation("Europe/Berlin") 35 36 return l 37 }(), 38 ), 39 TzDatetimeToTime, 40 }, 41 { 42 "TzTimestampToTime", 43 "2020-05-29T11:22:54.123456,Europe/Berlin", 44 time.Date(2020, time.May, 29, 11, 22, 54, 123456000, 45 func() *time.Location { 46 l, _ := time.LoadLocation("Europe/Berlin") 47 48 return l 49 }(), 50 ), 51 TzTimestampToTime, 52 }, 53 { 54 "TzTimestampToTime", 55 "2020-05-29T11:22:54,Europe/Berlin", 56 time.Date(2020, time.May, 29, 11, 22, 54, 0, 57 func() *time.Location { 58 l, _ := time.LoadLocation("Europe/Berlin") 59 60 return l 61 }(), 62 ), 63 TzTimestampToTime, 64 }, 65 } { 66 t.Run(tt.name, func(t *testing.T) { 67 v, err := tt.converter(tt.src) 68 require.NoError(t, err) 69 require.Equal(t, tt.exp, v, v.Format(LayoutDate)) 70 }) 71 } 72 }