hlc

package
v0.0.0-...-4dcfcdd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package hlc contains a trivial representation of CockroachDB's hybrid logical clock timestamp.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(a, b Time) int

Compare two timestamps.

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 RangeEmpty

func RangeEmpty() Range

RangeEmpty returns an empty range.

func RangeEmptyAt

func RangeEmptyAt(ts Time) Range

RangeEmptyAt returns a Range that starts at the given time, but for which Range.Empty will return true.

func RangeExcluding

func RangeExcluding(startInclusive, endExclusive Time) Range

RangeExcluding returns a Range that includes the start time and excludes the end time.

func RangeIncluding

func RangeIncluding(start, end Time) Range

RangeIncluding returns the smallest range that includes both the start and end times.

func (Range) Contains

func (r Range) Contains(t Time) bool

Contains returns true if the time provided is within this range.

func (Range) Empty

func (r Range) Empty() bool

Empty returns true if the Min time is greater than or equal to the Max value.

func (Range) Max

func (r Range) Max() Time

Max returns the exclusive, maximum value.

func (Range) MaxInclusive

func (r Range) MaxInclusive() Time

MaxInclusive returns the maximum value that is within the range. That is, it returns one tick before the exclusive end bound.

func (Range) Min

func (r Range) Min() Time

Min returns the inclusive, minimum value.

func (Range) String

func (r Range) String() string

func (Range) WithMin

func (r Range) WithMin(min Time) Range

WithMin returns a new range that includes the minimum. If the new minimum is equal to or beyond the end of the range, this is equivalent to calling RangeEmptyAt.

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 From

func From(t time.Time) Time

From constructs an HLC time from a wall time.

func New

func New(nanos int64, logical int) Time

New constructs a new Time with wall and logical parts.

func Parse

func Parse(timestamp string) (Time, error)

Parse splits a timestmap of the format NNNN.LLL into an int64 for the nanos and an int for the logical component.

func Zero

func Zero() Time

Zero returns a zero-valued Time.

func (Time) Before

func (t Time) Before() Time

Before returns the time minus one logical tick. If the time has a zero logical component, the previous nanosecond will be returned.

func (Time) Logical

func (t Time) Logical() int

Logical returns the logical counter.

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON represents the time as a JSON string. This is used when logging timestamps.

func (Time) Nanos

func (t Time) Nanos() int64

Nanos returns the nanosecond wall time.

func (Time) Next

func (t Time) Next() Time

Next returns the time plus one logical tick.

func (*Time) Scan

func (t *Time) Scan(src any) error

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) String

func (t Time) String() string

String returns the Time as a decimal-formatted string.

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON restores the timestamp from a string representation.

func (Time) Value

func (t Time) Value() (driver.Value, error)

Value implements driver.Valuer, which allows the time to be represented as a decimal string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL