本文整理匯總了Golang中github.com/pingcap/tidb/mysqldef.Time.Clock方法的典型用法代碼示例。如果您正苦於以下問題:Golang Time.Clock方法的具體用法?Golang Time.Clock怎麽用?Golang Time.Clock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pingcap/tidb/mysqldef.Time
的用法示例。
在下文中一共展示了Time.Clock方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: extractTime
func extractTime(unit string, t mysql.Time) (int64, error) {
switch strings.ToUpper(unit) {
case "MICROSECOND":
return int64(t.Nanosecond() / 1000), nil
case "SECOND":
return int64(t.Second()), nil
case "MINUTE":
return int64(t.Minute()), nil
case "HOUR":
return int64(t.Hour()), nil
case "DAY":
return int64(t.Day()), nil
case "WEEK":
_, week := t.ISOWeek()
return int64(week), nil
case "MONTH":
return int64(t.Month()), nil
case "QUARTER":
m := int64(t.Month())
// 1 - 3 -> 1
// 4 - 6 -> 2
// 7 - 9 -> 3
// 10 - 12 -> 4
return (m + 2) / 3, nil
case "YEAR":
return int64(t.Year()), nil
case "SECOND_MICROSECOND":
return int64(t.Second())*1000000 + int64(t.Nanosecond())/1000, nil
case "MINUTE_MICROSECOND":
_, m, s := t.Clock()
return int64(m)*100000000 + int64(s)*1000000 + int64(t.Nanosecond())/1000, nil
case "MINUTE_SECOND":
_, m, s := t.Clock()
return int64(m*100 + s), nil
case "HOUR_MICROSECOND":
h, m, s := t.Clock()
return int64(h)*10000000000 + int64(m)*100000000 + int64(s)*1000000 + int64(t.Nanosecond())/1000, nil
case "HOUR_SECOND":
h, m, s := t.Clock()
return int64(h)*10000 + int64(m)*100 + int64(s), nil
case "HOUR_MINUTE":
h, m, _ := t.Clock()
return int64(h)*100 + int64(m), nil
case "DAY_MICROSECOND":
h, m, s := t.Clock()
d := t.Day()
return int64(d*1000000+h*10000+m*100+s)*1000000 + int64(t.Nanosecond())/1000, nil
case "DAY_SECOND":
h, m, s := t.Clock()
d := t.Day()
return int64(d)*1000000 + int64(h)*10000 + int64(m)*100 + int64(s), nil
case "DAY_MINUTE":
h, m, _ := t.Clock()
d := t.Day()
return int64(d)*10000 + int64(h)*100 + int64(m), nil
case "DAY_HOUR":
h, _, _ := t.Clock()
d := t.Day()
return int64(d)*100 + int64(h), nil
case "YEAR_MONTH":
y, m, _ := t.Date()
return int64(y)*100 + int64(m), nil
default:
return 0, errors.Errorf("invalid unit %s", unit)
}
}