github.com/matrixorigin/matrixone@v0.7.0/pkg/vectorize/fromunixtime/from_unixtime_test.go (about) 1 // Copyright 2022 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package fromunixtime 16 17 import ( 18 "reflect" 19 "testing" 20 "time" 21 22 "github.com/matrixorigin/matrixone/pkg/container/types" 23 ) 24 25 func wantDatetimeFromUnix(ts int64) types.Datetime { 26 s := time.Unix(ts, 0).Local().Format("2006-01-02 15:04:05") 27 datetime, err := types.ParseDatetime(s, 6) 28 if err != nil { 29 panic("bad datetime") 30 } 31 return datetime 32 } 33 34 func TestFromUnixTimestamp(t *testing.T) { 35 xs := []int64{1641046980, 1641133380, 1641219780} 36 rs := make([]types.Datetime, 3) 37 want := []types.Datetime{ 38 wantDatetimeFromUnix(xs[0]), 39 wantDatetimeFromUnix(xs[1]), 40 wantDatetimeFromUnix(xs[2]), 41 } 42 43 got := unixToDatetime(time.Local, xs, rs) 44 if !reflect.DeepEqual(got, want) { 45 t.Errorf("unixtimestamp() want %v but got %v", want, got) 46 } 47 }