Upgrade gopkg.in/testfixtures.v2 (#4999)

This commit is contained in:
Mura Li 2018-10-03 03:20:02 +08:00 committed by techknowlogick
parent b8d048fa0d
commit dba955be7c
13 changed files with 708 additions and 171 deletions

View file

@ -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")
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 regexpDateTime.MatchString(str)
}
func isTime(value interface{}) bool {
str, isStr := value.(string)
if !isStr {
return false
}
return regexpTime.MatchString(str)
return time.Time{}, ErrCouldNotConvertToTime
}