Add "w" (weeks) as a valid timeunit.

This commit is contained in:
Julius Volz 2013-01-17 23:44:54 +01:00
parent 2c8595f96e
commit a555ded2b3
2 changed files with 6 additions and 2 deletions

View File

@ -55,7 +55,7 @@ func PopJob() {
}
func stringToDuration(durationStr string) time.Duration {
durationRE := regexp.MustCompile("([0-9]+)([ydhms]+)")
durationRE := regexp.MustCompile("^([0-9]+)([ywdhms]+)$")
matches := durationRE.FindStringSubmatch(durationStr)
if len(matches) != 3 {
configError("Not a valid duration string: '%v'", durationStr)
@ -65,6 +65,8 @@ func stringToDuration(durationStr string) time.Duration {
switch unit {
case "y":
value *= 60 * 60 * 24 * 365
case "w":
value *= 60 * 60 * 24 * 7
case "d":
value *= 60 * 60 * 24
case "h":

View File

@ -16,7 +16,7 @@ func rulesError(error string, v ...interface{}) error {
// TODO move to common place, currently duplicated in config/
func stringToDuration(durationStr string) (time.Duration, error) {
durationRE := regexp.MustCompile("([0-9]+)([ydhms]+)")
durationRE := regexp.MustCompile("^([0-9]+)([ywdhms]+)$")
matches := durationRE.FindStringSubmatch(durationStr)
if len(matches) != 3 {
return 0, rulesError("Not a valid duration string: '%v'", durationStr)
@ -26,6 +26,8 @@ func stringToDuration(durationStr string) (time.Duration, error) {
switch unit {
case "y":
value *= 60 * 60 * 24 * 365
case "w":
value *= 60 * 60 * 24
case "d":
value *= 60 * 60 * 24
case "h":