Update Vendors (#250)

update go min version

Update Vendors:
 * code.gitea.io/gitea-vet v0.2.0 -> v0.2.1
 * code.gitea.io/sdk/gitea v0.13.0 -> v0.13.1
 * github.com/AlecAivazis/survey v2.1.1 -> v2.2.2
 * github.com/adrg/xdg v0.2.1 -> v0.2.2
 * github.com/araddon/dateparse d820a6159ab1 -> 8aadafed4dc4
 * github.com/go-git/go-git v5.1.0 -> v5.2.0
 * github.com/muesli/termenv v0.7.2 -> v0.7.4
 * github.com/stretchr/testify v1.5.1 -> v1.6.1
 * github.com/urfave/cli v2.2.0 -> v2.3.0

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/tea/pulls/250
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: mrsdizzie <info@mrsdizzie.com>
Co-Authored-By: 6543 <6543@noreply.gitea.io>
Co-Committed-By: 6543 <6543@noreply.gitea.io>
This commit is contained in:
6543
2020-11-09 23:25:54 +08:00
parent 355fd7aa53
commit d5058b3b20
363 changed files with 36829 additions and 11815 deletions

View File

@@ -17,6 +17,23 @@ import (
// gou.SetColorOutput()
// }
var days = []string{
"mon",
"tue",
"wed",
"thu",
"fri",
"sat",
"sun",
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday",
"sunday",
}
var months = []string{
"january",
"february",
@@ -49,22 +66,24 @@ const (
dateDigitDot // 10
dateDigitDotDot
dateDigitSlash
dateDigitColon
dateDigitChineseYear
dateDigitChineseYearWs
dateDigitWs // 15
dateDigitChineseYearWs // 15
dateDigitWs
dateDigitWsMoYear
dateDigitWsMolong
dateAlpha
dateAlphaWs
dateAlphaWsDigit // 20
dateAlphaWs // 20
dateAlphaWsDigit
dateAlphaWsDigitMore
dateAlphaWsDigitMoreWs
dateAlphaWsDigitMoreWsYear
dateAlphaWsMonth
dateAlphaWsMonth // 25
dateAlphaWsDigitYearmaybe
dateAlphaWsMonthMore
dateAlphaWsMonthSuffix
dateAlphaWsMore
dateAlphaWsAtTime
dateAlphaWsAtTime // 30
dateAlphaWsAlpha
dateAlphaWsAlphaYearmaybe
dateAlphaPeriodWsDigit
@@ -120,8 +139,8 @@ func unknownErr(datestr string) error {
// ParseAny parse an unknown date format, detect the layout.
// Normal parse. Equivalent Timezone rules as time.Parse().
// NOTE: please see readme on mmdd vs ddmm ambiguous dates.
func ParseAny(datestr string) (time.Time, error) {
p, err := parseTime(datestr, nil)
func ParseAny(datestr string, opts ...ParserOption) (time.Time, error) {
p, err := parseTime(datestr, nil, opts...)
if err != nil {
return time.Time{}, err
}
@@ -133,8 +152,8 @@ func ParseAny(datestr string) (time.Time, error) {
// datestring, it uses the given location rules for any zone interpretation.
// That is, MST means one thing when using America/Denver and something else
// in other locations.
func ParseIn(datestr string, loc *time.Location) (time.Time, error) {
p, err := parseTime(datestr, loc)
func ParseIn(datestr string, loc *time.Location, opts ...ParserOption) (time.Time, error) {
p, err := parseTime(datestr, loc, opts...)
if err != nil {
return time.Time{}, err
}
@@ -156,8 +175,8 @@ func ParseIn(datestr string, loc *time.Location) (time.Time, error) {
//
// t, err := dateparse.ParseIn("3/1/2014", denverLoc)
//
func ParseLocal(datestr string) (time.Time, error) {
p, err := parseTime(datestr, time.Local)
func ParseLocal(datestr string, opts ...ParserOption) (time.Time, error) {
p, err := parseTime(datestr, time.Local, opts...)
if err != nil {
return time.Time{}, err
}
@@ -166,8 +185,8 @@ func ParseLocal(datestr string) (time.Time, error) {
// MustParse parse a date, and panic if it can't be parsed. Used for testing.
// Not recommended for most use-cases.
func MustParse(datestr string) time.Time {
p, err := parseTime(datestr, nil)
func MustParse(datestr string, opts ...ParserOption) time.Time {
p, err := parseTime(datestr, nil, opts...)
if err != nil {
panic(err.Error())
}
@@ -184,8 +203,8 @@ func MustParse(datestr string) time.Time {
// layout, err := dateparse.ParseFormat("2013-02-01 00:00:00")
// // layout = "2006-01-02 15:04:05"
//
func ParseFormat(datestr string) (string, error) {
p, err := parseTime(datestr, nil)
func ParseFormat(datestr string, opts ...ParserOption) (string, error) {
p, err := parseTime(datestr, nil, opts...)
if err != nil {
return "", err
}
@@ -198,8 +217,8 @@ func ParseFormat(datestr string) (string, error) {
// ParseStrict parse an unknown date format. IF the date is ambigous
// mm/dd vs dd/mm then return an error. These return errors: 3.3.2014 , 8/8/71 etc
func ParseStrict(datestr string) (time.Time, error) {
p, err := parseTime(datestr, nil)
func ParseStrict(datestr string, opts ...ParserOption) (time.Time, error) {
p, err := parseTime(datestr, nil, opts...)
if err != nil {
return time.Time{}, err
}
@@ -209,9 +228,31 @@ func ParseStrict(datestr string) (time.Time, error) {
return p.parse()
}
func parseTime(datestr string, loc *time.Location) (*parser, error) {
func parseTime(datestr string, loc *time.Location, opts ...ParserOption) (p *parser, err error) {
p = newParser(datestr, loc, opts...)
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
// by retrying in this case, we can fix a common situation with no assumptions
defer func() {
if p.ambiguousMD {
// if it errors out with the following error, swap before we
// get out of this function to reduce scope it needs to be applied on
_, err := p.parse()
if err != nil && strings.Contains(err.Error(), "month out of range") {
// create the option to reverse the preference
preferMonthFirst := PreferMonthFirst(!p.preferMonthFirst)
// turn off the retry to avoid endless recursion
retryAmbiguousDateWithSwap := RetryAmbiguousDateWithSwap(false)
modifiedOpts := append(opts, preferMonthFirst, retryAmbiguousDateWithSwap)
p, err = parseTime(datestr, time.Local, modifiedOpts...)
}
}
}()
}
p := newParser(datestr, loc)
i := 0
// General strategy is to read rune by rune through the date looking for
@@ -257,6 +298,31 @@ iterRunes:
// 03/31/2005
// 2014/02/24
p.stateDate = dateDigitSlash
if i == 4 {
p.yearlen = i
p.moi = i + 1
p.setYear()
} else {
p.ambiguousMD = true
if p.preferMonthFirst {
if p.molen == 0 {
p.molen = i
p.setMonth()
p.dayi = i + 1
}
} else {
if p.daylen == 0 {
p.daylen = i
p.setDay()
p.moi = i + 1
}
}
}
case ':':
// 03/31/2005
// 2014/02/24
p.stateDate = dateDigitColon
if i == 4 {
p.yearlen = i
p.moi = i + 1
@@ -446,6 +512,51 @@ iterRunes:
p.setDay()
p.yeari = i + 1
}
} else {
if p.molen == 0 {
p.molen = i - p.moi
p.setMonth()
p.yeari = i + 1
}
}
}
case dateDigitColon:
// 2014:07:10 06:55:38.156283
// 03:19:2012 10:11:59
// 04:2:2014 03:00:37
// 3:1:2012 10:11:59
// 4:8:2014 22:05
// 3:1:2014
// 10:13:2014
// 01:02:2006
// 1:2:06
switch r {
case ' ':
p.stateTime = timeStart
if p.yearlen == 0 {
p.yearlen = i - p.yeari
p.setYear()
} else if p.daylen == 0 {
p.daylen = i - p.dayi
p.setDay()
}
break iterRunes
case ':':
if p.yearlen > 0 {
// 2014:07:10 06:55:38.156283
if p.molen == 0 {
p.molen = i - p.moi
p.setMonth()
p.dayi = i + 1
}
} else if p.preferMonthFirst {
if p.daylen == 0 {
p.daylen = i - p.dayi
p.setDay()
p.yeari = i + 1
}
}
}
@@ -587,9 +698,21 @@ iterRunes:
} else {
// This is possibly ambiguous? May will parse as either though.
// So, it could return in-correct format.
// May 05, 2005, 05:05:05
// May 05 2005, 05:05:05
// Jul 05, 2005, 05:05:05
// dateAlphaWs
// May 05, 2005, 05:05:05
// May 05 2005, 05:05:05
// Jul 05, 2005, 05:05:05
// May 8 17:57:51 2009
// May 8 17:57:51 2009
// skip & return to dateStart
// Tue 05 May 2020, 05:05:05
// Mon Jan 2 15:04:05 2006
maybeDay := strings.ToLower(datestr[0:i])
if isDay(maybeDay) {
// using skip throws off indices used by other code; saner to restart
return parseTime(datestr[i+1:], loc)
}
p.stateDate = dateAlphaWs
}
@@ -618,7 +741,7 @@ iterRunes:
} else if i == 4 {
// gross
datestr = datestr[0:i-1] + datestr[i:]
return parseTime(datestr, loc)
return parseTime(datestr, loc, opts...)
} else {
return nil, unknownErr(datestr)
}
@@ -631,11 +754,14 @@ iterRunes:
// Mon Jan 02 15:04:05 -0700 2006
// Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)
// Mon Aug 10 15:44:11 UTC+0100 2015
// dateAlphaWsDigit
// May 8, 2009 5:57:51 PM
// May 8 2009 5:57:51 PM
// oct 1, 1970
// oct 7, '70
// dateAlphaWsDigit
// May 8, 2009 5:57:51 PM
// May 8 2009 5:57:51 PM
// May 8 17:57:51 2009
// May 8 17:57:51 2009
// May 08 17:57:51 2009
// oct 1, 1970
// oct 7, '70
switch {
case unicode.IsLetter(r):
p.set(0, "Mon")
@@ -653,6 +779,9 @@ iterRunes:
// oct 1, 1970
// oct 7, '70
// oct. 7, 1970
// May 8 17:57:51 2009
// May 8 17:57:51 2009
// May 08 17:57:51 2009
if r == ',' {
p.daylen = i - p.dayi
p.setDay()
@@ -661,11 +790,31 @@ iterRunes:
p.daylen = i - p.dayi
p.setDay()
p.yeari = i + 1
p.stateDate = dateAlphaWsDigitMoreWs
p.stateDate = dateAlphaWsDigitYearmaybe
p.stateTime = timeStart
} else if unicode.IsLetter(r) {
p.stateDate = dateAlphaWsMonthSuffix
i--
}
case dateAlphaWsDigitYearmaybe:
// x
// May 8 2009 5:57:51 PM
// May 8 17:57:51 2009
// May 8 17:57:51 2009
// May 08 17:57:51 2009
// Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)
if r == ':' {
// Guessed wrong; was not a year
i = i - 3
p.stateDate = dateAlphaWsDigit
p.yeari = 0
break iterRunes
} else if r == ' ' {
// must be year format, not 15:04
p.yearlen = i - p.yeari
p.setYear()
break iterRunes
}
case dateAlphaWsDigitMore:
// x
// May 8, 2009 5:57:51 PM
@@ -698,42 +847,6 @@ iterRunes:
break iterRunes
}
case dateAlphaWsAlpha:
// Mon Jan _2 15:04:05 2006
// Mon Jan 02 15:04:05 -0700 2006
// Mon Jan _2 15:04:05 MST 2006
// Mon Aug 10 15:44:11 UTC+0100 2015
// Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)
if r == ' ' {
if p.dayi > 0 {
p.daylen = i - p.dayi
p.setDay()
p.yeari = i + 1
p.stateDate = dateAlphaWsAlphaYearmaybe
p.stateTime = timeStart
}
} else if unicode.IsDigit(r) {
if p.dayi == 0 {
p.dayi = i
}
}
case dateAlphaWsAlphaYearmaybe:
// x
// Mon Jan _2 15:04:05 2006
// Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)
if r == ':' {
i = i - 3
p.stateDate = dateAlphaWsAlpha
p.yeari = 0
break iterRunes
} else if r == ' ' {
// must be year format, not 15:04
p.yearlen = i - p.yeari
p.setYear()
break iterRunes
}
case dateAlphaWsMonth:
// April 8, 2009
// April 8 2009
@@ -783,25 +896,25 @@ iterRunes:
case 't', 'T':
if p.nextIs(i, 'h') || p.nextIs(i, 'H') {
if len(datestr) > i+2 {
return parseTime(fmt.Sprintf("%s%s", p.datestr[0:i], p.datestr[i+2:]), loc)
return parseTime(fmt.Sprintf("%s%s", p.datestr[0:i], p.datestr[i+2:]), loc, opts...)
}
}
case 'n', 'N':
if p.nextIs(i, 'd') || p.nextIs(i, 'D') {
if len(datestr) > i+2 {
return parseTime(fmt.Sprintf("%s%s", p.datestr[0:i], p.datestr[i+2:]), loc)
return parseTime(fmt.Sprintf("%s%s", p.datestr[0:i], p.datestr[i+2:]), loc, opts...)
}
}
case 's', 'S':
if p.nextIs(i, 't') || p.nextIs(i, 'T') {
if len(datestr) > i+2 {
return parseTime(fmt.Sprintf("%s%s", p.datestr[0:i], p.datestr[i+2:]), loc)
return parseTime(fmt.Sprintf("%s%s", p.datestr[0:i], p.datestr[i+2:]), loc, opts...)
}
}
case 'r', 'R':
if p.nextIs(i, 'd') || p.nextIs(i, 'D') {
if len(datestr) > i+2 {
return parseTime(fmt.Sprintf("%s%s", p.datestr[0:i], p.datestr[i+2:]), loc)
return parseTime(fmt.Sprintf("%s%s", p.datestr[0:i], p.datestr[i+2:]), loc, opts...)
}
}
}
@@ -975,7 +1088,7 @@ iterRunes:
// 2014-05-11 08:20:13,787
ds := []byte(p.datestr)
ds[i] = '.'
return parseTime(string(ds), loc)
return parseTime(string(ds), loc, opts...)
case '-', '+':
// 03:21:51+00:00
p.stateTime = timeOffset
@@ -997,6 +1110,8 @@ iterRunes:
} else {
p.seclen = i - p.seci
}
// (Z)ulu time
p.loc = time.UTC
case 'a', 'A':
if p.nextIs(i, 't') || p.nextIs(i, 'T') {
// x
@@ -1139,7 +1254,9 @@ iterRunes:
switch r {
case ' ':
p.set(p.offseti, "-0700")
p.yeari = i + 1
if p.yeari == 0 {
p.yeari = i + 1
}
p.stateTime = timeWsAlphaZoneOffsetWs
}
case timeWsAlphaZoneOffsetWs:
@@ -1630,7 +1747,10 @@ iterRunes:
case dateAlphaWsAlpha:
return p, nil
case dateAlphaWsAlphaYearmaybe:
case dateAlphaWsDigit:
return p, nil
case dateAlphaWsDigitYearmaybe:
return p, nil
case dateDigitSlash:
@@ -1640,6 +1760,13 @@ iterRunes:
// 2014/10/13
return p, nil
case dateDigitColon:
// 3:1:2014
// 10:13:2014
// 01:02:2006
// 2014:10:13
return p, nil
case dateDigitChineseYear:
// dateDigitChineseYear
// 2014年04月08日
@@ -1667,48 +1794,75 @@ iterRunes:
}
type parser struct {
loc *time.Location
preferMonthFirst bool
ambiguousMD bool
stateDate dateState
stateTime timeState
format []byte
datestr string
fullMonth string
skip int
extra int
part1Len int
yeari int
yearlen int
moi int
molen int
dayi int
daylen int
houri int
hourlen int
mini int
minlen int
seci int
seclen int
msi int
mslen int
offseti int
offsetlen int
tzi int
tzlen int
t *time.Time
loc *time.Location
preferMonthFirst bool
retryAmbiguousDateWithSwap bool
ambiguousMD bool
stateDate dateState
stateTime timeState
format []byte
datestr string
fullMonth string
skip int
extra int
part1Len int
yeari int
yearlen int
moi int
molen int
dayi int
daylen int
houri int
hourlen int
mini int
minlen int
seci int
seclen int
msi int
mslen int
offseti int
offsetlen int
tzi int
tzlen int
t *time.Time
}
func newParser(dateStr string, loc *time.Location) *parser {
p := parser{
stateDate: dateStart,
stateTime: timeIgnore,
datestr: dateStr,
loc: loc,
preferMonthFirst: true,
// ParserOption defines a function signature implemented by options
// Options defined like this accept the parser and operate on the data within
type ParserOption func(*parser) error
// PreferMonthFirst is an option that allows preferMonthFirst to be changed from its default
func PreferMonthFirst(preferMonthFirst bool) ParserOption {
return func(p *parser) error {
p.preferMonthFirst = preferMonthFirst
return nil
}
}
// RetryAmbiguousDateWithSwap is an option that allows retryAmbiguousDateWithSwap to be changed from its default
func RetryAmbiguousDateWithSwap(retryAmbiguousDateWithSwap bool) ParserOption {
return func(p *parser) error {
p.retryAmbiguousDateWithSwap = retryAmbiguousDateWithSwap
return nil
}
}
func newParser(dateStr string, loc *time.Location, opts ...ParserOption) *parser {
p := &parser{
stateDate: dateStart,
stateTime: timeIgnore,
datestr: dateStr,
loc: loc,
preferMonthFirst: true,
retryAmbiguousDateWithSwap: false,
}
p.format = []byte(dateStr)
return &p
// allow the options to mutate the parser fields from their defaults
for _, option := range opts {
option(p)
}
return p
}
func (p *parser) nextIs(i int, b byte) bool {
@@ -1854,6 +2008,14 @@ func (p *parser) parse() (time.Time, error) {
}
return time.ParseInLocation(string(p.format), p.datestr, p.loc)
}
func isDay(alpha string) bool {
for _, day := range days {
if alpha == day {
return true
}
}
return false
}
func isMonthFull(alpha string) bool {
for _, month := range months {
if alpha == month {