naturaldate

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2020 License: MIT Imports: 7 Imported by: 29

README

Go Natural Date

Natural date time parsing for Go. This package was designed for parsing human-friendly relative date/time ranges in Apex Logs' command-line log search.

Examples

Here are some examples of the types of expressions currently supported, arbitrary text is currently ignored.

  • now
  • today
  • yesterday
  • 5 minutes ago
  • three days ago
  • last month
  • next month
  • one year from now
  • yesterday at 10am
  • last sunday at 5:30pm
  • sunday at 22:45
  • next January
  • last February
  • December 25th at 7:30am
  • 10am
  • 10:05pm
  • 10:05:22pm
  • Restart the server in 5 days from now
  • Remind me on the 25th of December at 7:30am
  • Message me in two weeks
  • See the tests for more examples

Direction

A default direction can be applied using WithDirection() for ambiguous expressions such as sunday, or september. By default naturaldate.Past is used, so they will be equivalent to last sunday and last september.


GoDoc

Sponsors

This project is sponsored by CTO.ai, making it easy for development teams to create and share workflow automations without leaving the command line.

And my GitHub sponsors:

Documentation

Overview

Package naturaldate provides natural date time parsing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(s string, ref time.Time, options ...Option) (time.Time, error)

Parse query string.

func Pretty

func Pretty(pretty bool) func(*parser) error

func Size

func Size(size int) func(*parser) error

Types

type Direction

type Direction int

Direction is the direction used for ambiguous expressions.

const (
	Past Direction = iota
	Future
)

Directions available.

type Option

type Option func(*parser)

Option function.

func WithDirection

func WithDirection(d Direction) Option

WithDirection sets the direction used for ambiguous expressions. By default the Past direction is used, so "sunday" will be the previous Sunday, rather than the next Sunday.

Jump to

Keyboard shortcuts

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