timeutil

package
v0.9.12 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(s string) (int64, error)

Parse converts a time string to a unix timestamp (seconds). Supported formats:

  • Go duration (relative to now): "5m", "1h", "24h", "168h" Interpreted as "now minus duration"
  • Future duration with "+" prefix: "+24h", "+7d" Interpreted as "now plus duration"
  • Day shorthand: "7d", "30d" — converted to hours automatically
  • Date: "2026-04-01" (parsed as local midnight)
  • Datetime: "2026-04-01 10:00:00" or "2026-04-01T10:00:00" (parsed as local time)
  • RFC3339 with timezone: "2026-04-01T10:00:00+08:00" / "...Z" (the format the SDK emits)
  • Unix timestamp: "1712000000" (passed through)

func ParseAny

func ParseAny(v any) (int64, error)

ParseAny accepts the same string formats as Parse, plus raw numeric unix seconds (any of float64, int, int64). Empty string and nil return 0 with no error so callers can distinguish "not provided" from a parse failure.

This exists because MCP arguments arrive as map[string]any: LLM-friendly callers pass strings ("24h"), while legacy callers and e2e tests pass raw int64. Both paths must work without forcing every call site to branch on type.

Types

This section is empty.

Jump to

Keyboard shortcuts

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