Update common/model vendoring

pull/1357/head
beorn7 2016-01-29 15:30:57 +01:00
parent d9f836e5b8
commit cfc15cf103
2 changed files with 14 additions and 4 deletions

View File

@ -163,10 +163,10 @@ func (t *Time) UnmarshalJSON(b []byte) error {
// This type should not propagate beyond the scope of input/output processing. // This type should not propagate beyond the scope of input/output processing.
type Duration time.Duration type Duration time.Duration
var durationRE = regexp.MustCompile("^([0-9]+)(d|h|m|s|ms)$") var durationRE = regexp.MustCompile("^([0-9]+)(y|w|d|h|m|s|ms)$")
// StringToDuration parses a string into a time.Duration, assuming that a year // StringToDuration parses a string into a time.Duration, assuming that a year
// a day always has 24h. // always has 365d, a week always has 7d, and a day always has 24h.
func ParseDuration(durationStr string) (Duration, error) { func ParseDuration(durationStr string) (Duration, error) {
matches := durationRE.FindStringSubmatch(durationStr) matches := durationRE.FindStringSubmatch(durationStr)
if len(matches) != 3 { if len(matches) != 3 {
@ -177,6 +177,10 @@ func ParseDuration(durationStr string) (Duration, error) {
dur = time.Duration(n) * time.Millisecond dur = time.Duration(n) * time.Millisecond
) )
switch unit := matches[2]; unit { switch unit := matches[2]; unit {
case "y":
dur *= 1000 * 60 * 60 * 24 * 365
case "w":
dur *= 1000 * 60 * 60 * 24 * 7
case "d": case "d":
dur *= 1000 * 60 * 60 * 24 dur *= 1000 * 60 * 60 * 24
case "h": case "h":
@ -199,6 +203,8 @@ func (d Duration) String() string {
unit = "ms" unit = "ms"
) )
factors := map[string]int64{ factors := map[string]int64{
"y": 1000 * 60 * 60 * 24 * 365,
"w": 1000 * 60 * 60 * 24 * 7,
"d": 1000 * 60 * 60 * 24, "d": 1000 * 60 * 60 * 24,
"h": 1000 * 60 * 60, "h": 1000 * 60 * 60,
"m": 1000 * 60, "m": 1000 * 60,
@ -207,6 +213,10 @@ func (d Duration) String() string {
} }
switch int64(0) { switch int64(0) {
case ms % factors["y"]:
unit = "y"
case ms % factors["w"]:
unit = "w"
case ms % factors["d"]: case ms % factors["d"]:
unit = "d" unit = "d"
case ms % factors["h"]: case ms % factors["h"]:

4
vendor/vendor.json vendored
View File

@ -174,8 +174,8 @@
}, },
{ {
"path": "github.com/prometheus/common/model", "path": "github.com/prometheus/common/model",
"revision": "b0d797186bfbaf6d785031c6c2d32f75c720007d", "revision": "0e53cc19aa67dd2e8587a26e28643cb152f5403d",
"revisionTime": "2016-01-22T12:15:42+01:00" "revisionTime": "2016-01-29T15:16:16+01:00"
}, },
{ {
"path": "github.com/prometheus/common/route", "path": "github.com/prometheus/common/route",