mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-24 19:30:06 +01:00
21170e558c
This should prevent from bugs similar to https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5801 in the future
This is a follow-up for ce3ec3ff2e
30 lines
691 B
Go
30 lines
691 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
|
|
)
|
|
|
|
const (
|
|
// These values prevent from overflow when storing msec-precision time in int64.
|
|
minTimeMsecs = 0 // use 0 instead of `int64(-1<<63) / 1e6` because the storage engine doesn't actually support negative time
|
|
maxTimeMsecs = int64(1<<63-1) / 1e6
|
|
)
|
|
|
|
func parseTime(s string) (time.Time, error) {
|
|
msecs, err := promutils.ParseTimeMsec(s)
|
|
if err != nil {
|
|
return time.Time{}, fmt.Errorf("cannot parse %s: %w", s, err)
|
|
}
|
|
if msecs < minTimeMsecs {
|
|
msecs = 0
|
|
}
|
|
if msecs > maxTimeMsecs {
|
|
msecs = maxTimeMsecs
|
|
}
|
|
|
|
return time.Unix(0, msecs*int64(time.Millisecond)).UTC(), nil
|
|
}
|