mirror of
https://github.com/go-gitea/gitea.git
synced 2025-09-17 17:20:06 +00:00
Upgrade gopkg.in/testfixtures.v2 (#4999)
This commit is contained in:
54
vendor/gopkg.in/testfixtures.v2/time.go
generated
vendored
54
vendor/gopkg.in/testfixtures.v2/time.go
generated
vendored
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user