Documentation ¶
Index ¶
- Constants
- Variables
- func CalIntervalRatio(queryInterval, storageInterval int64) int
- func CalPointCount(startTime, endTime, interval int64) int
- func CalcTimestamp(startTime int64, slot int, interval Interval) int64
- func FormatTimestamp(timestamp int64, layout string) string
- func Now() int64
- func NowNano() int64
- func ParseTimestamp(timestampStr string, layout ...string) (int64, error)
- func Truncate(timestamp, interval int64) int64
- type Interval
- func (i Interval) CalcSlotRange(familyTime int64, timeRange TimeRange) SlotRange
- func (i Interval) Calculator() IntervalCalculator
- func (i Interval) Int64() int64
- func (i *Interval) MarshalJSON() (data []byte, err error)
- func (i Interval) MarshalText() (text []byte, err error)
- func (i Interval) String() string
- func (i Interval) Type() IntervalType
- func (i *Interval) UnmarshalJSON(data []byte) (err error)
- func (i *Interval) UnmarshalText(text []byte) error
- func (i *Interval) ValueOf(intervalStr string) error
- type IntervalCalculator
- type IntervalType
- type SlotRange
- type TimeRange
Constants ¶
const ( // OneSecond is the number of millisecond for a second OneSecond int64 = 1000 // OneMinute is the number of millisecond for a minute OneMinute = 60 * OneSecond // OneHour is the number of millisecond for an hour OneHour = 60 * OneMinute // OneDay is the number of millisecond for a day OneDay = 24 * OneHour // OneWeek is the number of millisecond for a week OneWeek = 7 * OneDay // OneMonth is the number of millisecond for a month OneMonth = 30 * OneDay // OneYear is the number of millisecond for a year OneYear = 365 * OneDay DataTimeFormat1 = "20060102 15:04:05" DataTimeFormat2 = "2006-01-02 15:04:05" DataTimeFormat3 = "2006/01/02 15:04:05" DataTimeFormat4 = "20060102150405" )
Variables ¶
var ErrUnknownInterval = errors.New("unknown interval")
Functions ¶
func CalIntervalRatio ¶
CalIntervalRatio calculates the interval ratio for query, if query interval < storage interval return 1.
func CalPointCount ¶
CalPointCount calculates point counts between start time and end time by interval
func CalcTimestamp ¶
CalcTimestamp returns timestamp based on start time, slot and interval.
func FormatTimestamp ¶
FormatTimestamp returns timestamp format based on layout
func Now ¶
func Now() int64
Now returns t as a Unix time, the number of millisecond elapsed since January 1, 1970 UTC. The result does not depend on the location associated with t.
func NowNano ¶
func NowNano() int64
NowNano returns t as a unix time, the number of nanoseconds elapsed
func ParseTimestamp ¶
ParseTimestamp parses timestamp str value based on layout using local zone
Types ¶
type Interval ¶
type Interval int64
Interval is the interval value in millisecond
func CalcQueryInterval ¶
CalcQueryInterval returns query interval based on query time range and interval.
func (Interval) CalcSlotRange ¶
CalcSlotRange returns slot range by family time and time range.
func (Interval) Calculator ¶
func (i Interval) Calculator() IntervalCalculator
Calculator returns the calculator for current interval.
func (*Interval) MarshalJSON ¶
MarshalJSON converts an interval to a string for decoding json
func (Interval) MarshalText ¶
MarshalText converts an interval to a string for decoding toml
func (Interval) Type ¶
func (i Interval) Type() IntervalType
func (*Interval) UnmarshalJSON ¶
UnmarshalJSON parses a JSON value into an interval value.
func (*Interval) UnmarshalText ¶
UnmarshalText parses a TOML value into an interval value. See https://github.com/BurntSushi/toml
type IntervalCalculator ¶
type IntervalCalculator interface { // GetSegment returns segment name by given timestamp GetSegment(timestamp int64) string // ParseSegmentTime parses segment base time based on given segment name ParseSegmentTime(segmentName string) (int64, error) // CalcSegmentTime calculates segment base time based on given segment name CalcSegmentTime(timestamp int64) int64 // CalcFamily calculates family base time based on given timestamp CalcFamily(timestamp, segmentTime int64) int // CalcFamilyTime calculates family base time based on given timestamp CalcFamilyTime(timestamp int64) int64 // CalcFamilyStartTime calculates family start time based on segment time and family time CalcFamilyStartTime(segmentTime int64, familyTime int) int64 // CalcFamilyEndTime calculates family end time based on family start time CalcFamilyEndTime(familyStartTime int64) int64 // CalcSlot calculates field store slot index based on given timestamp and base time CalcSlot(timestamp, baseTime, interval int64) int // CalcTimeWindows calculates the number of time window between start and end time CalcTimeWindows(start, end int64) int }
IntervalCalculator calculates the timestamp for each interval type
type IntervalType ¶
type IntervalType string
IntervalType defines interval type
const ( Day IntervalType = "day" Month IntervalType = "month" Year IntervalType = "year" Unknown IntervalType = "unknown" )
Interval types.
type SlotRange ¶
type SlotRange struct {
Start, End uint16
}
SlotRange represents time range with start/end timestamp using low value.
func NewSlotRange ¶
NewSlotRange creates a new slot range with start/end
type TimeRange ¶
TimeRange represents time range with start/end timestamp.