timeutil

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package timeutil converts human-friendly time expressions into the microsecond Unix timestamps OpenObserve's search API expects.

This is deliberately the CLI's job, not the agent's: hand-computing microsecond epochs is the single most error-prone part of calling the search API, so the CLI owns it and accepts forgiving inputs (--since 1h, RFC3339, bare dates, epoch seconds/millis/micros, and now±duration expressions).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromMicros

func FromMicros(us int64) time.Time

FromMicros converts Unix microseconds back to a UTC time.Time.

func ParseFlexDuration

func ParseFlexDuration(s string) (time.Duration, error)

ParseFlexDuration parses a duration string. In addition to Go's native units (s, m, h) it understands d (days) and w (weeks), e.g. "15m", "2h", "7d".

func ParseInstant

func ParseInstant(s string, now time.Time) (time.Time, error)

ParseInstant parses a single point in time relative to now. It accepts:

  • "now" → now
  • "now-1h" / "now+30m" → now ± duration (supports d/w units)
  • a bare duration "1h" / "2d" → that long ago (now - duration)
  • RFC3339 / RFC3339 with zone → as written
  • "2006-01-02" (UTC midnight) and "2006-01-02 15:04:05" (UTC)
  • an integer epoch in seconds, milliseconds or microseconds (auto-detected)

func ToMicros

func ToMicros(t time.Time) int64

ToMicros converts a time.Time to Unix microseconds.

Types

type Range

type Range struct {
	Since string
	From  string
	To    string
	Now   time.Time
}

Range is an unresolved time window described by flags. Exactly one of Since or (From/To) is normally provided. Now, when zero, defaults to time.Now() — tests set it for determinism.

func (Range) Resolve

func (r Range) Resolve() (startMicros, endMicros int64, err error)

Resolve turns the Range into start/end microsecond timestamps. The window is validated to be non-empty and correctly ordered.

Jump to

Keyboard shortcuts

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