Documentation ¶
Overview ¶
Package hlc contains a trivial representation of CockroachDB's hybrid logical clock timestamp.
Index ¶
- func Compare(a, b Time) int
- type Range
- type Time
- func (t Time) Before() Time
- func (t Time) Logical() int
- func (t Time) MarshalJSON() ([]byte, error)
- func (t Time) Nanos() int64
- func (t Time) Next() Time
- func (t *Time) Scan(src any) error
- func (t Time) String() string
- func (t *Time) UnmarshalJSON(data []byte) error
- func (t Time) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Range ¶
type Range [2]Time
Range represents a half-open range of HLC values, inclusive of Min and exclusive of Max. For code readability, prefer using RangeEmpty or RangeIncluding to construct ranges instead of directly creating a Range.
func RangeEmptyAt ¶
RangeEmptyAt returns a Range that starts at the given time, but for which Range.Empty will return true.
func RangeExcluding ¶
RangeExcluding returns a Range that includes the start time and excludes the end time.
func RangeIncluding ¶
RangeIncluding returns the smallest range that includes both the start and end times.
func (Range) Extend ¶
Extend returns a range that contains the given time by adjusting either the minimum or the maximum time as necessary.
func (Range) MaxInclusive ¶
MaxInclusive returns the maximum value that is within the range. That is, it returns one tick before the exclusive end bound.
type Time ¶
type Time struct {
// contains filtered or unexported fields
}
Time is a representation of the hybrid logical clock timestamp used by CockroachDB. This is an immutable value type, suitable for use as a map key.
func Parse ¶
Parse splits a timestmap of the format NNNN.LLL into an int64 for the nanos and an int for the logical component.
func (Time) Before ¶
Before returns the time minus one logical tick. If the time has a zero logical component, the previous nanosecond will be returned.
func (Time) MarshalJSON ¶
MarshalJSON represents the time as a JSON string. This is used when logging timestamps.
func (*Time) Scan ¶
Scan implements sql.Scanner and attempts to parse the input as a decimal-formatted string. This method also has a special case to handle a single "0" as input.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON restores the timestamp from a string representation.