本文整理匯總了Golang中github.com/pingcap/tidb/mysqldef.Time.Time方法的典型用法代碼示例。如果您正苦於以下問題:Golang Time.Time方法的具體用法?Golang Time.Time怎麽用?Golang Time.Time使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pingcap/tidb/mysqldef.Time
的用法示例。
在下文中一共展示了Time.Time方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: dumpBinaryDateTime
func dumpBinaryDateTime(t mysql.Time, loc *time.Location) (data []byte) {
if t.Type == mysql.TypeTimestamp && loc != nil {
t.Time = t.In(loc)
}
switch t.Type {
case mysql.TypeTimestamp, mysql.TypeDatetime:
data = append(data, 11)
data = append(data, dumpUint16(uint16(t.Year()))...) //year
data = append(data, byte(t.Month()), byte(t.Day()), byte(t.Hour()), byte(t.Minute()), byte(t.Second()))
data = append(data, dumpUint32(uint32((t.Nanosecond() / 1000)))...)
case mysql.TypeDate, mysql.TypeNewDate:
data = append(data, 4)
data = append(data, dumpUint16(uint16(t.Year()))...) //year
data = append(data, byte(t.Month()), byte(t.Day()))
}
return
}
示例2: getTimeValue
func getTimeValue(ctx context.Context, v interface{}, tp byte, fsp int) (interface{}, error) {
value := mysql.Time{
Type: tp,
Fsp: fsp,
}
defaultTime, err := getSystemTimestamp(ctx)
if err != nil {
return nil, errors.Trace(err)
}
switch x := v.(type) {
case string:
if x == CurrentTimestamp {
value.Time = defaultTime
} else if x == ZeroTimestamp {
value, _ = mysql.ParseTimeFromNum(0, tp, fsp)
} else {
value, err = mysql.ParseTime(x, tp, fsp)
if err != nil {
return nil, errors.Trace(err)
}
}
case Value:
switch xval := x.Val.(type) {
case string:
value, err = mysql.ParseTime(xval, tp, fsp)
if err != nil {
return nil, errors.Trace(err)
}
case int64:
value, err = mysql.ParseTimeFromNum(int64(xval), tp, fsp)
if err != nil {
return nil, errors.Trace(err)
}
case nil:
return nil, nil
default:
return nil, errors.Trace(errDefaultValue)
}
case *Ident:
if x.Equal(CurrentTimeExpr) {
return CurrentTimestamp, nil
}
return nil, errors.Trace(errDefaultValue)
case *UnaryOperation:
// support some expression, like `-1`
m := map[interface{}]interface{}{}
v := Eval(x, nil, m)
ft := types.NewFieldType(mysql.TypeLonglong)
xval, err := types.Convert(v, ft)
if err != nil {
return nil, errors.Trace(err)
}
value, err = mysql.ParseTimeFromNum(xval.(int64), tp, fsp)
if err != nil {
return nil, errors.Trace(err)
}
default:
return nil, nil
}
return value, nil
}