GoLang Parse many date strings without knowing format in advance.
GoLang Parse many date strings without knowing format in advance.
Parse many date strings without knowing format in advance. Uses a scanner to read bytes and use a state machine to find format. Much faster than shotgun based parse methods. See bench_test.go for performance comparison.
MM/DD/YYYY VS DD/MM/YYYY Right now this uses mm/dd/yyyy WHEN ambiguous if this is not desired behavior, use ParseStrict which will fail on ambiguous date strings.
Timezones The location your server is configured affects the results! See example or https://play.golang.org/p/IDHRalIyXh and last paragraph here https://golang.org/pkg/time/#Parse.
// Normal parse. Equivalent Timezone rules as time.Parse()
t, err := dateparse.ParseAny("3/1/2014")
// Parse Strict, error on ambigous mm/dd vs dd/mm dates
t, err := dateparse.ParseStrict("3/1/2014")
> returns error
// Return a string that represents the layout to parse the given date-time.
layout, err := dateparse.ParseFormat("May 8, 2009 5:57:51 PM")
> "Jan 2, 2006 3:04:05 PM"
https://github.com/araddon/dateparse/blob/master/example/main.go
…No open issues yet, or sync has not completed.