Copyright 2013 The Prometheus Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

package model

import (
	
	
	
	
	
	
)

MinimumTick is the minimum supported time resolution. This has to be at least time.Second in order for the code below to work.
second is the Time duration equivalent to one second.
The number of nanoseconds per minimum tick.
Earliest is the earliest Time representable. Handy for initializing a high watermark.
Latest is the latest Time representable. Handy for initializing a low watermark.
Time is the number of milliseconds since the epoch (1970-01-01 00:00 UTC) excluding leap seconds.
type Time int64
Interval describes an interval between two timestamps.
type Interval struct {
	Start, End Time
}
Now returns the current time as a Time.
func () Time {
	return TimeFromUnixNano(time.Now().UnixNano())
}
TimeFromUnix returns the Time equivalent to the Unix Time t provided in seconds.
func ( int64) Time {
	return Time( * second)
}
TimeFromUnixNano returns the Time equivalent to the Unix Time t provided in nanoseconds.
func ( int64) Time {
	return Time( / nanosPerTick)
}
Equal reports whether two Times represent the same instant.
func ( Time) ( Time) bool {
	return  == 
}
Before reports whether the Time t is before o.
func ( Time) ( Time) bool {
	return  < 
}
After reports whether the Time t is after o.
func ( Time) ( Time) bool {
	return  > 
}
Add returns the Time t + d.
func ( Time) ( time.Duration) Time {
	return  + Time(/minimumTick)
}
Sub returns the Duration t - o.
func ( Time) ( Time) time.Duration {
	return time.Duration(-) * minimumTick
}
Time returns the time.Time representation of t.
func ( Time) () time.Time {
	return time.Unix(int64()/second, (int64()%second)*nanosPerTick)
}
Unix returns t as a Unix time, the number of seconds elapsed since January 1, 1970 UTC.
func ( Time) () int64 {
	return int64() / second
}
UnixNano returns t as a Unix time, the number of nanoseconds elapsed since January 1, 1970 UTC.
func ( Time) () int64 {
	return int64() * nanosPerTick
}
The number of digits after the dot.
String returns a string representation of the Time.
func ( Time) () string {
	return strconv.FormatFloat(float64()/float64(second), 'f', -1, 64)
}
MarshalJSON implements the json.Marshaler interface.
func ( Time) () ([]byte, error) {
	return []byte(.String()), nil
}
UnmarshalJSON implements the json.Unmarshaler interface.
func ( *Time) ( []byte) error {
	 := strings.Split(string(), ".")
	switch len() {
	case 1:
		,  := strconv.ParseInt(string([0]), 10, 64)
		if  != nil {
			return 
		}
		* = Time( * second)

	case 2:
		,  := strconv.ParseInt(string([0]), 10, 64)
		if  != nil {
			return 
		}
		 *= second

		 := dotPrecision - len([1])
		if  < 0 {
			[1] = [1][:dotPrecision]
		} else if  > 0 {
			[1] = [1] + strings.Repeat("0", )
		}

		,  := strconv.ParseInt([1], 10, 32)
		if  != nil {
			return 
		}
If the value was something like -0.1 the negative is lost in the parsing because of the leading zero, this ensures that we capture it.
		if len([0]) > 0 && [0][0] == '-' && + > 0 {
			* = Time(+) * -1
		} else {
			* = Time( + )
		}

	default:
		return fmt.Errorf("invalid time %q", string())
	}
	return nil
}
Duration wraps time.Duration. It is used to parse the custom duration format from YAML. This type should not propagate beyond the scope of input/output processing.
Set implements pflag/flag.Value
func ( *Duration) ( string) error {
	var  error
	*,  = ParseDuration()
	return 
}
Type implements pflag.Value
func ( *Duration) () string {
	return "duration"
}

var durationRE = regexp.MustCompile("^([0-9]+)(y|w|d|h|m|s|ms)$")
ParseDuration parses a string into a time.Duration, assuming that a year always has 365d, a week always has 7d, and a day always has 24h.
func ( string) (Duration, error) {
	 := durationRE.FindStringSubmatch()
	if len() != 3 {
		return 0, fmt.Errorf("not a valid duration string: %q", )
	}
	var (
		,  = strconv.Atoi([1])
		  = time.Duration() * time.Millisecond
	)
	switch  := [2];  {
	case "y":
		 *= 1000 * 60 * 60 * 24 * 365
	case "w":
		 *= 1000 * 60 * 60 * 24 * 7
	case "d":
		 *= 1000 * 60 * 60 * 24
	case "h":
		 *= 1000 * 60 * 60
	case "m":
		 *= 1000 * 60
	case "s":
		 *= 1000
Value already correct
	default:
		return 0, fmt.Errorf("invalid time unit in duration string: %q", )
	}
	return Duration(), nil
}

func ( Duration) () string {
	var (
		   = int64(time.Duration() / time.Millisecond)
		 = "ms"
	)
	if  == 0 {
		return "0s"
	}
	 := map[string]int64{
		"y":  1000 * 60 * 60 * 24 * 365,
		"w":  1000 * 60 * 60 * 24 * 7,
		"d":  1000 * 60 * 60 * 24,
		"h":  1000 * 60 * 60,
		"m":  1000 * 60,
		"s":  1000,
		"ms": 1,
	}

	switch int64(0) {
	case  % ["y"]:
		 = "y"
	case  % ["w"]:
		 = "w"
	case  % ["d"]:
		 = "d"
	case  % ["h"]:
		 = "h"
	case  % ["m"]:
		 = "m"
	case  % ["s"]:
		 = "s"
	}
	return fmt.Sprintf("%v%v", /[], )
}
MarshalYAML implements the yaml.Marshaler interface.
func ( Duration) () (interface{}, error) {
	return .String(), nil
}
UnmarshalYAML implements the yaml.Unmarshaler interface.
func ( *Duration) ( func(interface{}) error) error {
	var  string
	if  := (&);  != nil {
		return 
	}
	,  := ParseDuration()
	if  != nil {
		return 
	}
	* = 
	return nil