intimate/utils.go
eson fe25921f9a fix: ParseDuration Method
add: store UpdateOperator
2020-07-16 16:22:14 +08:00

45 lines
653 B
Go

package intimate
import (
"log"
"time"
)
var zeroTime time.Time
func init() {
tm, err := time.Parse("15:04:05", "0:00:00")
if err != nil {
log.Println(err)
}
zeroTime = tm
}
// ParseDuration time to duration eg: 1:40:00 -> time.Duration
func ParseDuration(dt string) (time.Duration, error) {
var parse []byte = []byte("00:00:00")
j := len(parse) - 1
for i := len(dt) - 1; i >= 0; i-- {
c := dt[i]
if c != ':' {
parse[j] = dt[i]
} else {
for parse[j] != ':' {
j--
}
}
j--
}
tdt, err := time.Parse("15:04:05", string(parse))
if err != nil {
return time.Duration(0), err
}
return tdt.Sub(zeroTime), nil
}