2020-04-03 23:11:33 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"regexp"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2020-04-20 21:03:38 +00:00
|
|
|
// ErrTimeoutReached error thrown when a timeout is reached.
|
2020-04-03 23:11:33 +00:00
|
|
|
var ErrTimeoutReached = errors.New("timeout reached")
|
|
|
|
var parseDurationRegexp = regexp.MustCompile(`^(?P<Duration>[1-9]\d*?)(?P<Unit>[smhdwMy])?$`)
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// Hour is an int based representation of the time unit.
|
2020-04-03 23:11:33 +00:00
|
|
|
const Hour = time.Minute * 60
|
2020-04-20 21:03:38 +00:00
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// Day is an int based representation of the time unit.
|
2020-04-03 23:11:33 +00:00
|
|
|
const Day = Hour * 24
|
2020-04-20 21:03:38 +00:00
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// Week is an int based representation of the time unit.
|
2020-04-03 23:11:33 +00:00
|
|
|
const Week = Day * 7
|
2020-04-20 21:03:38 +00:00
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// Year is an int based representation of the time unit.
|
2020-04-03 23:11:33 +00:00
|
|
|
const Year = Day * 365
|
2020-04-20 21:03:38 +00:00
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// Month is an int based representation of the time unit.
|
2020-04-03 23:11:33 +00:00
|
|
|
const Month = Year / 12
|