date

package
v0.1.48 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	KnownFormats = []string{
		"MMM D, YYYY h:mm:ss P",
		"DDD MMM _D HH:mm:ss YYYY",
		"DDD MMM _D HH:mm:ss MST YYYY",
		"DDD MMM DD HH:mm:ss ZZZZ YYYY",
		"DDDD, YY-MMM-DD HH:mm:ss ZZZ",
		"DDD, DD MMM YYYY HH:mm:ss ZZZ",
		"DDD, DD MMM YYYY HH:mm:ss ZZZZ",
		"DDD, D MMM YYYY HH:mm:ss ZZZZ",
		"DD MMM YYYY, HH:mm",
		"YYYY-MMM-DD",
		"DD MMMM YYYY",

		"DD/MM/YYYY HH:mm:ss.SSS",
		"DD/MM/YYYY HH:mm:ss",
		"D/MM/YYYY HH:mm:ss",
		"DD/M/YYYY HH:mm:ss",
		"D/M/YYYY HH:mm:ss",
		"D/M/YYYY hh:mm:ss P",
		"DD/MM/YYYY HH:mm",
		"D/M/YYYY HH:mm",
		"D/M/YY HH:mm",
		"D/M/YYYY hh:mm P",
		"D/M/YYYY h:mm P",
		"DD/MMM/YYYY:HH:mm:ss ZZZZ",
		"DD/MM/YYYY",
		"D/MM/YYYY",
		"DD/MM/YY",
		"D/M/YY",

		"YYYY/MM/DD HH:mm:ss.SSS",
		"YYYY/MM/DD HH:mm:ss",
		"YYYY/MM/D HH:mm:ss",
		"YYYY/M/DD HH:mm:ss",
		"YYYY/MM/DD HH:mm",
		"YYYY/M/D HH:mm",
		"YYYY/MM/DD",
		"YYYY/M/DD",

		"YYYY-MM-DDTHH:mm:ss.SSSZZZZ",
		"YYYY-MM-DDTHH:mm:ss.SSSZ",
		"YYYY-MM-DDTHH:mm:ssZZZZZ",
		"YYYY-MM-DDTHH:mm:ssZZZZ",
		"YYYY-MM-DDTHH:mm:ssZ",
		"YYYY-MM-DDTHH:mm:ss",

		"YYYY-MM-DD HH:mm:ss.SSS ZZZZ ZZZ",
		"YYYY-MM-DD HH:mm:ss.SSS",
		"YYYY-MM-DD HH:mm:ss ZZZZZ",
		"YYYY-MM-DD HH:mm:ssZZZZZ",
		"YYYY-MM-DD HH:mm:ss ZZZZ ZZZ",
		"YYYY-MM-DD HH:mm:ss ZZZZ",
		"YYYY-MM-DD HH:mm:ss ZZZ",
		"YYYY-MM-DD hh:mm:ss P",
		"YYYY-MM-DD HH:mm:ss",
		"YYYY-MM-DD  HH:mm:ss",
		"YYYY-MM-DD HH:mm",
		"YYYY-MM-DD",

		"MM.DD.YYYY",
		"MM.DD.YY",

		"DDD MMM _D HH:mm:ss.SSS",
		"DDD MMM DD HH:mm:ss.SSS",
		"MMM DD HH:mm:ss",
		"MMM _D HH:mm:ss",
	}
)

Functions

func NewDefaultParser

func NewDefaultParser(usrFmts ...string) *parser

NewDefaultParser creates new default parser using either known formats or the formats provided

func NewParser

func NewParser(fmts ...string) *parser

NewParser builds new parser with the give formats

func Parse

func Parse(data []byte) (time.Time, error)

Parse pass data though a default parser and returns the date it is found there

Types

type Format

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

func (*Format) GetFormat

func (f *Format) GetFormat() string

func (*Format) Parse

func (f *Format) Parse(buf []byte) (tm time.Time, err error)

type Parser

type Parser interface {
	Parse(buf []byte) (time.Time, *Format)
}

Parser parses the given byte slice in accordance with the date formats it has, returns parsed out date (leftmost only) and format which can be used to parse similarly formatted dates. In case if no suitable format can be found empty time.Time object is returned.

NOTE: Since date portion search in the given slice is based on regexp it can consume considerable amount of CPU cycles (depends on the number of formats the current parser has).

Jump to

Keyboard shortcuts

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