39 lines
644 B
Go
39 lines
644 B
Go
package scheduler
|
|
|
|
import (
|
|
"errors"
|
|
"reflect"
|
|
"runtime"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// for given function fn, get the name of function.
|
|
func getFunctionName(fn interface{}) string {
|
|
return runtime.FuncForPC(reflect.ValueOf((fn)).Pointer()).Name()
|
|
}
|
|
|
|
func formatTime(t string) (hour, min int, err error) {
|
|
var er = errors.New("time format error")
|
|
ts := strings.Split(t, ":")
|
|
if len(ts) != 2 {
|
|
err = er
|
|
return
|
|
}
|
|
|
|
hour, err = strconv.Atoi(ts[0])
|
|
if err != nil {
|
|
return
|
|
}
|
|
min, err = strconv.Atoi(ts[1])
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if hour < 0 || hour > 23 || min < 0 || min > 59 {
|
|
err = er
|
|
return
|
|
}
|
|
return hour, min, nil
|
|
}
|