natural

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package natural implements the internal natural-language parsing layer for gotime. It uses only standard-library time types so it can stay decoupled from the parent package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	// Locale is the BCP 47 locale tag used to select a parser.
	Locale string
	// RelativeTo carries already-projected civil fields in UTC for safe calendar math.
	RelativeTo time.Time
}

Context provides the parsing environment, using only stdlib types.

type Kind

type Kind uint8

Kind classifies the semantic output of natural language parsing.

const (
	// KindDate is a calendar date without a clock time.
	KindDate Kind = iota + 1
	// KindDateTime is unresolved civil date-time intent.
	KindDateTime
	// KindDuration is an elapsed relative duration.
	KindDuration
	// KindPeriod is a calendar relative period.
	KindPeriod
	// KindAmbiguous represents multiple valid interpretations.
	KindAmbiguous
	// KindInvalid represents a parse failure.
	KindInvalid
)

type Result

type Result struct {
	// Kind classifies the parsed value.
	Kind Kind
	// Civil components hold Date and DateTime results without resolving a zone.
	Year       int
	Month      time.Month
	Day        int
	Hour       int
	Minute     int
	Second     int
	Nanosecond int
	// NeedsReference reports whether the result was resolved from Context.RelativeTo.
	NeedsReference bool
	// DurNanos is the parsed duration when Kind is KindDuration.
	DurNanos int64
	// Period fields hold calendar offsets when Kind is KindPeriod.
	PeriodYears  int32
	PeriodMonths int32
	PeriodDays   int32
	// Candidates holds the alternative interpretations when Kind is KindAmbiguous.
	Candidates []Result
	// ErrCode is the stable error code when Kind is KindInvalid.
	ErrCode string
	// ErrMessage is the human-readable error summary when Kind is KindInvalid.
	ErrMessage string
	// ErrHint explains how to fix the invalid input when Kind is KindInvalid.
	ErrHint string
}

Result is the intermediate parse output.

func Parse

func Parse(input string, ctx Context) (Result, bool)

Parse dispatches to the locale-appropriate parser. It returns (result, true) when a registered parser recognizes the input.

Jump to

Keyboard shortcuts

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