diff --git a/bench_test.go b/bench_test.go index 0c6739a..575d795 100644 --- a/bench_test.go +++ b/bench_test.go @@ -28,7 +28,7 @@ func BenchmarkShotgunParse(b *testing.B) { for i := 0; i < b.N; i++ { for _, dateStr := range testDates { // This is the non dateparse traditional approach - parseShotgunStyle(dateStr) + _ = parseShotgunStyle(dateStr) } } } @@ -37,7 +37,7 @@ func BenchmarkParseAny(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { for _, dateStr := range testDates { - ParseAny(dateStr) + _ = ParseAny(dateStr) } } } diff --git a/go.mod b/go.mod index 071cd5e..3376d23 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/araddon/dateparse -go 1.12 +go 1.19 require ( github.com/mattn/go-runewidth v0.0.10 // indirect diff --git a/parseany.go b/parseany.go index b9668b2..3214143 100644 --- a/parseany.go +++ b/parseany.go @@ -234,7 +234,10 @@ func ParseStrict(datestr string, opts ...ParserOption) (time.Time, error) { func parseTime(datestr string, loc *time.Location, opts ...ParserOption) (p *parser, err error) { - p = newParser(datestr, loc, opts...) + p, err = newParser(datestr, loc, opts...) + if err != nil { + return + } if p.retryAmbiguousDateWithSwap { // month out of range signifies that a day/month swap is the correct solution to an ambiguous date // this is because it means that a day is being interpreted as a month and overflowing the valid value for that @@ -2008,7 +2011,7 @@ func RetryAmbiguousDateWithSwap(retryAmbiguousDateWithSwap bool) ParserOption { } } -func newParser(dateStr string, loc *time.Location, opts ...ParserOption) *parser { +func newParser(dateStr string, loc *time.Location, opts ...ParserOption) (*parser, error) { p := &parser{ stateDate: dateStart, stateTime: timeIgnore, @@ -2021,7 +2024,9 @@ func newParser(dateStr string, loc *time.Location, opts ...ParserOption) *parser // allow the options to mutate the parser fields from their defaults for _, option := range opts { - option(p) + if err := option(p); err != nil { + return nil, fmt.Sprintf("option error: %w", err) + } } return p }