natural

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 5 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
	// ZoneID is the IANA zone ID or fixed offset used for relative expressions.
	ZoneID string
	// RelativeTo is the reference time for relative expressions.
	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 a zoned local date-time.
	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
	// Time is the resolved time for KindDate and KindDateTime results.
	Time time.Time
	// DateOnly reports whether Time should be interpreted as a date without a clock time.
	DateOnly bool
	// ZoneID is the zone associated with the result when one applies.
	ZoneID string
	// 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