diff --git a/cast_test.go b/cast_test.go index 016f8c2..6bea164 100644 --- a/cast_test.go +++ b/cast_test.go @@ -897,6 +897,17 @@ func BenchmarkTrimZeroDecimal(b *testing.B) { } } +func BenchmarkCommonTimeLayouts(b *testing.B) { + for i := 0; i < b.N; i++ { + for _, commonLayout := range []string{"2019-04-29", "2017-05-30T00:00:00Z"} { + _, err := StringToDateInDefaultLocation(commonLayout, time.UTC) + if err != nil { + b.Fatal(err) + } + } + } +} + func TestIndirectPointers(t *testing.T) { c := qt.New(t) diff --git a/caste.go b/caste.go index bccf27a..d49bbf8 100644 --- a/caste.go +++ b/caste.go @@ -1406,6 +1406,8 @@ func (f timeFormat) hasTimezone() bool { var ( timeFormats = []timeFormat{ + // Keep common formats at the top. + {"2006-01-02", timeFormatNoTimezone}, {time.RFC3339, timeFormatNumericTimezone}, {"2006-01-02T15:04:05", timeFormatNoTimezone}, // iso8601 without timezone {time.RFC1123Z, timeFormatNumericTimezone}, @@ -1421,7 +1423,6 @@ var ( {time.UnixDate, timeFormatNamedTimezone}, {time.RubyDate, timeFormatNumericTimezone}, {"2006-01-02 15:04:05Z07:00", timeFormatNumericTimezone}, - {"2006-01-02", timeFormatNoTimezone}, {"02 Jan 2006", timeFormatNoTimezone}, {"2006-01-02 15:04:05 -07:00", timeFormatNumericTimezone}, {"2006-01-02 15:04:05 -0700", timeFormatNumericTimezone},