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:
3
vendor/github.com/araddon/dateparse/.travis.yml
generated
vendored
3
vendor/github.com/araddon/dateparse/.travis.yml
generated
vendored
@@ -1,8 +1,7 @@
|
||||
language: go
|
||||
|
||||
go:
|
||||
- 1.10.x
|
||||
- 1.11.x
|
||||
- 1.13.x
|
||||
|
||||
before_install:
|
||||
- go get -t -v ./...
|
||||
|
||||
16
vendor/github.com/araddon/dateparse/README.md
generated
vendored
16
vendor/github.com/araddon/dateparse/README.md
generated
vendored
@@ -66,7 +66,9 @@ var examples = []string{
|
||||
"Tue, 11 Jul 2017 16:28:13 +0200 (CEST)",
|
||||
"Mon, 02 Jan 2006 15:04:05 -0700",
|
||||
"Thu, 4 Jan 2018 17:53:36 +0000",
|
||||
"Mon 30 Sep 2018 09:09:09 PM UTC",
|
||||
"Mon Aug 10 15:44:11 UTC+0100 2015",
|
||||
"Thu, 4 Jan 2018 17:53:36 +0000",
|
||||
"Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)",
|
||||
"September 17, 2012 10:09am",
|
||||
"September 17, 2012 at 10:09am PST-08",
|
||||
@@ -106,6 +108,15 @@ var examples = []string{
|
||||
"2014/4/02 03:00:51",
|
||||
"2012/03/19 10:11:59",
|
||||
"2012/03/19 10:11:59.3186369",
|
||||
// yyyy:mm:dd
|
||||
"2014:3:31",
|
||||
"2014:03:31",
|
||||
"2014:4:8 22:05",
|
||||
"2014:04:08 22:05",
|
||||
"2014:04:2 03:00:51",
|
||||
"2014:4:02 03:00:51",
|
||||
"2012:03:19 10:11:59",
|
||||
"2012:03:19 10:11:59.3186369",
|
||||
// Chinese
|
||||
"2014年04月08日",
|
||||
// yyyy-mm-ddThh
|
||||
@@ -199,8 +210,9 @@ func main() {
|
||||
| Mon, 02 Jan 2006 15:04:05 MST | 2006-01-02 15:04:05 +0000 MST |
|
||||
| Tue, 11 Jul 2017 16:28:13 +0200 (CEST) | 2017-07-11 16:28:13 +0200 +0200 |
|
||||
| Mon, 02 Jan 2006 15:04:05 -0700 | 2006-01-02 15:04:05 -0700 -0700 |
|
||||
| Thu, 4 Jan 2018 17:53:36 +0000 | 2018-01-04 17:53:36 +0000 UTC |
|
||||
| Mon 30 Sep 2018 09:09:09 PM UTC | 2018-09-30 21:09:09 +0000 UTC |
|
||||
| Mon Aug 10 15:44:11 UTC+0100 2015 | 2015-08-10 15:44:11 +0000 UTC |
|
||||
| Thu, 4 Jan 2018 17:53:36 +0000 | 2018-01-04 17:53:36 +0000 UTC |
|
||||
| Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time) | 2015-07-03 18:04:07 +0100 GMT |
|
||||
| September 17, 2012 10:09am | 2012-09-17 10:09:00 +0000 UTC |
|
||||
| September 17, 2012 at 10:09am PST-08 | 2012-09-17 10:09:00 -0800 PST |
|
||||
@@ -238,7 +250,7 @@ func main() {
|
||||
| 2014/4/02 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
|
||||
| 2012/03/19 10:11:59 | 2012-03-19 10:11:59 +0000 UTC |
|
||||
| 2012/03/19 10:11:59.3186369 | 2012-03-19 10:11:59.3186369 +0000 UTC |
|
||||
| 2014年04月08日 | 2014-04-08 00:00:00 +0000 UTC |
|
||||
| 2014年04月08日 | 2014-04-08 00:00:00 +0000 UTC |
|
||||
| 2006-01-02T15:04:05+0000 | 2006-01-02 15:04:05 +0000 UTC |
|
||||
| 2009-08-12T22:15:09-07:00 | 2009-08-12 22:15:09 -0700 -0700 |
|
||||
| 2009-08-12T22:15:09 | 2009-08-12 22:15:09 +0000 UTC |
|
||||
|
||||
9
vendor/github.com/araddon/dateparse/go.mod
generated
vendored
Normal file
9
vendor/github.com/araddon/dateparse/go.mod
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
module github.com/araddon/dateparse
|
||||
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/mattn/go-runewidth v0.0.9 // indirect
|
||||
github.com/scylladb/termtables v0.0.0-20191203121021-c4c0b6d42ff4
|
||||
github.com/stretchr/testify v1.6.1
|
||||
)
|
||||
15
vendor/github.com/araddon/dateparse/go.sum
generated
vendored
Normal file
15
vendor/github.com/araddon/dateparse/go.sum
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/scylladb/termtables v0.0.0-20191203121021-c4c0b6d42ff4 h1:8qmTC5ByIXO3GP/IzBkxcZ/99VITvnIETDhdFz/om7A=
|
||||
github.com/scylladb/termtables v0.0.0-20191203121021-c4c0b6d42ff4/go.mod h1:C1a7PQSMz9NShzorzCiG2fk9+xuCgLkPeCvMHYR2OWg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
384
vendor/github.com/araddon/dateparse/parseany.go
generated
vendored
384
vendor/github.com/araddon/dateparse/parseany.go
generated
vendored
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user