2020-07-15 07:44:21 +00:00
|
|
|
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) {
|
2020-07-16 08:22:14 +00:00
|
|
|
|
|
|
|
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))
|
2020-07-15 07:44:21 +00:00
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return time.Duration(0), err
|
|
|
|
}
|
|
|
|
return tdt.Sub(zeroTime), nil
|
|
|
|
}
|