mirror of
https://github.com/araddon/dateparse.git
synced 2025-01-19 11:16:12 +08:00
Error return value is not checked (errcheck)
This commit is contained in:
parent
26d95ba3e6
commit
5335e6fe23
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
2
go.mod
2
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
|
||||
|
11
parseany.go
11
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user