github.com/matrixorigin/matrixone@v0.7.0/pkg/vectorize/time/time.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 time 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/common/moerr" 19 "github.com/matrixorigin/matrixone/pkg/container/types" 20 ) 21 22 func DateToTime(xs []types.Date, rs []types.Time) []types.Time { 23 for i, x := range xs { 24 rs[i] = x.ToTime() 25 } 26 return rs 27 } 28 29 func DatetimeToTime(xs []types.Datetime, rs []types.Time, precision int32) []types.Time { 30 for i, x := range xs { 31 rs[i] = x.ToTime(precision) 32 } 33 return rs 34 } 35 36 func DateStringToTime(xs []string, rs []types.Time) ([]types.Time, error) { 37 for i, str := range xs { 38 t, e := types.ParseTime(str, 6) 39 if e != nil { 40 return rs, moerr.NewOutOfRangeNoCtx("date", "'%s'", str) 41 } 42 rs[i] = t 43 } 44 return rs, nil 45 } 46 47 func Int64ToTime(xs []int64, rs []types.Time) ([]types.Time, error) { 48 for i, s := range xs { 49 t, e := types.ParseInt64ToTime(s, 0) 50 if e != nil { 51 return rs, moerr.NewOutOfRangeNoCtx("time", "'%d'", s) 52 } 53 rs[i] = t 54 } 55 return rs, nil 56 } 57 58 func Decimal128ToTime(xs []types.Decimal128, rs []types.Time) ([]types.Time, error) { 59 for i, s := range xs { 60 t, e := types.ParseDecimal128lToTime(s, 6) 61 if e != nil { 62 return rs, moerr.NewOutOfRangeNoCtx("time", "'%s'", s) 63 } 64 rs[i] = t 65 } 66 return rs, nil 67 }