mirror of
https://github.com/prometheus/prometheus
synced 2026-05-01 07:30:30 +08:00
Add "w" (weeks) as a valid timeunit.
This commit is contained in:
@@ -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":
|
||||
|
||||
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user