Source File
time.go
Belonging Package
github.com/prometheus/common/model
package model
import (
)
func () Time {
return TimeFromUnixNano(time.Now().UnixNano())
}
func ( int64) Time {
return Time( / nanosPerTick)
}
func ( Time) () int64 {
return int64() * nanosPerTick
}
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
}
func ( *Duration) ( string) error {
var error
*, = ParseDuration()
return
}
func ( *Duration) () string {
return "duration"
}
var durationRE = regexp.MustCompile("^([0-9]+)(y|w|d|h|m|s|ms)$")
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
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", /[], )
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |