diff options
Diffstat (limited to 'vendor/gopkg.in/testfixtures.v2/time.go')
-rw-r--r-- | vendor/gopkg.in/testfixtures.v2/time.go | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/vendor/gopkg.in/testfixtures.v2/time.go b/vendor/gopkg.in/testfixtures.v2/time.go index 6796707500..8c5cba1d03 100644 --- a/vendor/gopkg.in/testfixtures.v2/time.go +++ b/vendor/gopkg.in/testfixtures.v2/time.go @@ -1,36 +1,34 @@ package testfixtures -import "regexp" - -var ( - regexpDate = regexp.MustCompile("\\d\\d\\d\\d-\\d\\d-\\d\\d") - regexpDateTime = regexp.MustCompile("\\d\\d\\d\\d-\\d\\d-\\d\\d \\d\\d:\\d\\d:\\d\\d") - regexpTime = regexp.MustCompile("\\d\\d:\\d\\d:\\d\\d") +import ( + "errors" + "time" ) -func isDate(value interface{}) bool { - str, isStr := value.(string) - if !isStr { - return false - } - - return regexpDate.MatchString(str) +var timeFormats = []string{ + "2006-01-02", + "2006-01-02 15:04", + "2006-01-02 15:04:05", + "20060102", + "20060102 15:04", + "20060102 15:04:05", + "02/01/2006", + "02/01/2006 15:04", + "02/01/2006 15:04:05", + "2006-01-02T15:04-07:00", + "2006-01-02T15:04:05-07:00", } -func isDateTime(value interface{}) bool { - str, isStr := value.(string) - if !isStr { - return false - } +// ErrCouldNotConvertToTime is returns when a string is not a reconizable time format +var ErrCouldNotConvertToTime = errors.New("Could not convert string to time") - return regexpDateTime.MatchString(str) -} - -func isTime(value interface{}) bool { - str, isStr := value.(string) - if !isStr { - return false +func tryStrToDate(s string) (time.Time, error) { + for _, f := range timeFormats { + t, err := time.ParseInLocation(f, s, time.Local) + if err != nil { + continue + } + return t, nil } - - return regexpTime.MatchString(str) + return time.Time{}, ErrCouldNotConvertToTime } |