nano

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: BSD-3-Clause Imports: 7 Imported by: 9

Documentation

Index

Constants

View Source
const (
	Nanosecond  Duration = 1
	Microsecond          = 1000 * Nanosecond
	Millisecond          = 1000 * Microsecond
	Second               = 1000 * Millisecond
	Minute               = 60 * Second
	Hour                 = 60 * Minute
	Day                  = 24 * Hour
	Week                 = 7 * Day
	Year                 = 365 * Day
)

Variables

View Source
var MaxSpan = Span{Ts: 0, Dur: math.MaxInt64}

MaxSpan is a range from the minimum possible time to the max possible time.

Functions

This section is empty.

Types

type Duration

type Duration int64

func DurationFromParts

func DurationFromParts(sec, ns int64) Duration

func MinDurForDay

func MinDurForDay(minDur Duration, fanout int) Duration

func ParseDuration

func ParseDuration(s string) (Duration, error)

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (Duration) String

func (d Duration) String() string

func (Duration) Trunc added in v1.0.0

func (d Duration) Trunc(bin Duration) Duration

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

type Span

type Span struct {
	Ts  Ts       `json:"ts" zed:"ts"`
	Dur Duration `json:"dur" zed:"dur"`
}

Span represents a time span. Spans are half-open: [Ts, Ts + Dur).

func NewSpanTs

func NewSpanTs(start, end Ts) Span

NewSpanTs creates a Span from a Ts pair. The Span is half-open: [start, end).

func (Span) Contains

func (s Span) Contains(ts Ts) bool

Contains returns true if the timestamp is in the time interval.

func (Span) ContainsClosed

func (s Span) ContainsClosed(ts Ts) bool

ContainsClose returns true if the timestamp is in the time interval including the end of interval.

func (Span) Covers

func (s Span) Covers(covered Span) bool

Covers returns true if the passed span is covered by s.

func (Span) End

func (s Span) End() Ts

End returns the first Ts after the Span (in other words, the smallest Ts greater than every Ts in the Span).

func (Span) Intersect

func (s Span) Intersect(b Span) Span

Intersect merges two spans returning a new span representing the intesection of the two spans. If the spans do not overlap, a zero valued span is returned.

func (Span) MinDur

func (s Span) MinDur(minDur Duration, fanout int) Duration

MinDur returns the smallest duration >= minDur among spans that would be partioned in a span tree of degree fanout.

func (Span) Overlaps

func (s Span) Overlaps(comp Span) bool

Overlaps returns true if the two spans overlap.

func (Span) OverlapsOrAdjacent

func (s Span) OverlapsOrAdjacent(comp Span) bool

OverlapsOrAdjacent returns true if the two spans overlaps each or are adjacent.

func (Span) Partition

func (s Span) Partition(ts Ts, n int) int

Partition divides the span into n subspans of approximately equal length and returns the index of the subspan containing ts.

func (Span) Pretty

func (s Span) Pretty() string

func (Span) String

func (s Span) String() string

func (Span) SubSpan

func (s Span) SubSpan(i, n int) Span

SubSpan divides the span into n subspans of approximately equal length and returns the i-th.

func (Span) Subtract

func (s Span) Subtract(b Span) []Span

Subtract returns a slice of spans that represent the receiver span minus the time ranges of the input span. Assumes the two spans overlap.

func (Span) Union

func (s Span) Union(b Span) Span

Union merges two spans returning a new span where start equals min(a.start, b.start) and end equals max(a.end, b.end). Assumes the two spans overlap.

type Ts

type Ts int64
const (
	MinTs Ts = 0
	MaxTs Ts = math.MaxInt64
)

func Date

func Date(year int, month time.Month, day, hour, min, sec, nsec int) Ts

func Now

func Now() Ts

func ParseMillis

func ParseMillis(s []byte) (Ts, error)

ParseMillis parses an unsigned integer representing milliseconds since the Unix epoch.

func ParseRFC3339Nano

func ParseRFC3339Nano(s []byte) (Ts, error)

ParseRFC3339Nano parses a byte according to the time.RFC3339Nano format into a Ts, returning an error if parsing failed.

func TimeToTs

func TimeToTs(t time.Time) Ts

convert a golang time to a nano Ts

func Unix

func Unix(sec, ns int64) Ts

Unix returns a Ts corresponding to the given Unix time, sec seconds and nsec nanoseconds since January 1, 1970 UTC.

func (Ts) Add

func (t Ts) Add(d Duration) Ts

func (Ts) DayOf

func (t Ts) DayOf() Span

func (Ts) MarshalJSON

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

func (Ts) Midnight

func (t Ts) Midnight() Ts

func (Ts) Pretty

func (t Ts) Pretty() string

func (Ts) Split

func (t Ts) Split() (int64, int64)

Split returns the seconds and nanoseconds since epoch of the timestamp.

func (Ts) String

func (t Ts) String() string

func (Ts) Sub

func (t Ts) Sub(d Duration) Ts

func (Ts) SubTs

func (t Ts) SubTs(u Ts) Duration

SubTs returns the duration t-u.

func (Ts) Time

func (t Ts) Time() time.Time

func (Ts) Trunc

func (t Ts) Trunc(bin Duration) Ts

func (*Ts) UnmarshalJSON

func (t *Ts) UnmarshalJSON(in []byte) error

Jump to

Keyboard shortcuts

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