dateparse

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(s string, now time.Time, cfg Config) (*time.Time, error)

Parse parses string s relative to the point in time now and configuration cfg. Returns (*time.Time, nil) on success, (nil, nil) for an empty/null string, (nil, error) for an unrecognised non-empty input. Uses Russian language patterns.

Types

type Config

type Config struct {
	TimeOfDay          TimeOfDay
	Weekdays           []time.Weekday // empty = Mon..Fri; others are weekends
	NightCutoffMinutes int            // 0 = off; if now < cutoff, relative offsets ≥1 are shifted by -1
}

Config holds date-parsing parameters.

type DateLanguage

type DateLanguage interface {
	Parse(expr string, now time.Time, cfg Config) (time.Time, bool)
}

DateLanguage parses language-specific temporal expressions.

func NewDateLanguage

func NewDateLanguage(lang string) DateLanguage

NewDateLanguage returns a DateLanguage for the given language code. Falls back to Russian for unknown languages.

type Dateparser

type Dateparser struct {
	// contains filtered or unexported fields
}

Dateparser parses deadline expressions using a language-aware module.

func New

func New(cfg Config, lang DateLanguage) *Dateparser

New creates a Dateparser for the given config and language.

func (*Dateparser) Parse

func (d *Dateparser) Parse(s string, now time.Time) (*time.Time, error)

Parse parses string s relative to the point in time now. Returns (*time.Time, nil) on success, (nil, nil) for an empty/null string, (nil, error) for an unrecognised non-empty input.

type TimeOfDay

type TimeOfDay struct {
	Morning   int
	Lunch     int
	Afternoon int
	Evening   int
	Default   int // hour applied when a date is given without an explicit time
}

TimeOfDay defines the hours of day for time-of-day phrase parsing.

Jump to

Keyboard shortcuts

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