From a555ded2b362ddad4186b4e409011d122a503c6a Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Thu, 17 Jan 2013 23:44:54 +0100 Subject: [PATCH] Add "w" (weeks) as a valid timeunit. --- config/helpers.go | 4 +++- rules/helpers.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/config/helpers.go b/config/helpers.go index 77277b4c4..450f12b10 100644 --- a/config/helpers.go +++ b/config/helpers.go @@ -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": diff --git a/rules/helpers.go b/rules/helpers.go index 11dc66643..3dca4ef21 100644 --- a/rules/helpers.go +++ b/rules/helpers.go @@ -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":