Improve golint happiness

This commit is contained in:
Aaron Raddon 2017-08-12 09:48:28 -07:00
parent a1537bb044
commit febb340f9d
2 changed files with 198 additions and 202 deletions

View File

@ -10,62 +10,62 @@ import (
type dateState int type dateState int
const ( const (
st_START dateState = iota stateStart dateState = iota
st_DIGIT stateDigit
st_DIGITDASH stateDigitDash
st_DIGITDASHALPHA stateDigitDashAlpha
st_DIGITDASHWS stateDigitDashWs
st_DIGITDASHWSWS stateDigitDashWsWs
st_DIGITDASHWSWSAMPMMAYBE stateDigitDashWsWsAMPMMaybe
st_DIGITDASHWSWSOFFSET stateDigitDashWsWsOffset
st_DIGITDASHWSWSOFFSETALPHA stateDigitDashWsWsOffsetAlpha
st_DIGITDASHWSWSOFFSETCOLONALPHA stateDigitDashWsWsOffsetColonAlpha
st_DIGITDASHWSWSOFFSETCOLON stateDigitDashWsWsOffsetColon
st_DIGITDASHWSOFFSET stateDigitDashWsOffset
st_DIGITDASHWSWSALPHA stateDigitDashWsWsAlpha
st_DIGITDASHWSDOT stateDigitDashWsPeriod
st_DIGITDASHWSDOTALPHA stateDigitDashWsPeriodAlpha
st_DIGITDASHWSDOTOFFSET stateDigitDashWsPeriodOffset
st_DIGITDASHWSDOTOFFSETALPHA stateDigitDashWsPeriodOffsetAlpha
st_DIGITDASHT stateDigitDashT
st_DIGITDASHTZ stateDigitDashTZ
st_DIGITDASHTZDIGIT stateDigitDashTZDigit
st_DIGITDASHTDELTA stateDigitDashTOffset
st_DIGITDASHTDELTACOLON stateDigitDashTOffsetColon
st_DIGITSLASH stateDigitSlash
st_DIGITSLASHWS stateDigitSlashWS
st_DIGITSLASHWSCOLON stateDigitSlashWSColon
st_DIGITSLASHWSCOLONAMPM stateDigitSlashWSColonAMPM
st_DIGITSLASHWSCOLONCOLON stateDigitSlashWSColonColon
st_DIGITSLASHWSCOLONCOLONAMPM stateDigitSlashWSColonColonAMPM
st_DIGITALPHA stateDigitAlpha
st_ALPHA stateAlpha
st_ALPHAWS stateAlphaWS
st_ALPHAWSDIGITCOMMA stateAlphaWSDigitComma
st_ALPHAWSALPHA stateAlphaWSAlpha
st_ALPHAWSALPHACOLON stateAlphaWSAlphaColon
st_ALPHAWSALPHACOLONOFFSET stateAlphaWSAlphaColonOffset
st_ALPHAWSALPHACOLONALPHA stateAlphaWSAlphaColonAlpha
st_ALPHAWSALPHACOLONALPHAOFFSET stateAlphaWSAlphaColonAlphaOffset
st_ALPHAWSALPHACOLONALPHAOFFSETALPHA stateAlphaWSAlphaColonAlphaOffsetAlpha
st_WEEKDAYCOMMA stateWeekdayComma
st_WEEKDAYCOMMADELTA stateWeekdayCommaOffset
st_WEEKDAYABBREVCOMMA stateWeekdayAbbrevComma
st_WEEKDAYABBREVCOMMADELTA stateWeekdayAbbrevCommaOffset
st_WEEKDAYABBREVCOMMADELTAZONE stateWeekdayAbbrevCommaOffsetZone
) )
var ( var (
shortDates = []string{"01/02/2006", "1/2/2006", "06/01/02", "01/02/06", "1/2/06"} shortDates = []string{"01/02/2006", "1/2/2006", "06/01/02", "01/02/06", "1/2/06"}
) )
// Given an unknown date format, detect the layout, parse. // ParseAny parse an unknown date format, detect the layout, parse.
// Normal parse. Equivalent Timezone rules as time.Parse() // Normal parse. Equivalent Timezone rules as time.Parse()
func ParseAny(datestr string) (time.Time, error) { func ParseAny(datestr string) (time.Time, error) {
return parseTime(datestr, nil) return parseTime(datestr, nil)
} }
// Parse with Location, equivalent to time.ParseInLocation() timezone/offset // ParseIn with Location, equivalent to time.ParseInLocation() timezone/offset
// rules. Using location arg, if timezone/offset info exists in the // rules. Using location arg, if timezone/offset info exists in the
// datestring, it uses the given location rules for any zone interpretation. // datestring, it uses the given location rules for any zone interpretation.
// That is, MST means one thing when using America/Denver and something else // That is, MST means one thing when using America/Denver and something else
@ -93,8 +93,8 @@ func ParseLocal(datestr string) (time.Time, error) {
return parseTime(datestr, time.Local) return parseTime(datestr, time.Local)
} }
// Parse a date, and panic if it can't be parsed. Used for testing. // MustParse parse a date, and panic if it can't be parsed. Used for testing.
// Not recomended for most use-cases. // Not recommended for most use-cases.
func MustParse(datestr string) time.Time { func MustParse(datestr string) time.Time {
t, err := parseTime(datestr, nil) t, err := parseTime(datestr, nil)
if err != nil { if err != nil {
@ -111,7 +111,7 @@ func parse(layout, datestr string, loc *time.Location) (time.Time, error) {
} }
func parseTime(datestr string, loc *time.Location) (time.Time, error) { func parseTime(datestr string, loc *time.Location) (time.Time, error) {
state := st_START state := stateStart
firstSlash := 0 firstSlash := 0
@ -128,27 +128,27 @@ iterRunes:
// } // }
switch state { switch state {
case st_START: case stateStart:
if unicode.IsDigit(r) { if unicode.IsDigit(r) {
state = st_DIGIT state = stateDigit
} else if unicode.IsLetter(r) { } else if unicode.IsLetter(r) {
state = st_ALPHA state = stateAlpha
} }
case st_DIGIT: // starts digits case stateDigit: // starts digits
if unicode.IsDigit(r) { if unicode.IsDigit(r) {
continue continue
} else if unicode.IsLetter(r) { } else if unicode.IsLetter(r) {
state = st_DIGITALPHA state = stateDigitAlpha
continue continue
} }
switch r { switch r {
case '-', '\u2212': case '-', '\u2212':
state = st_DIGITDASH state = stateDigitDash
case '/': case '/':
state = st_DIGITSLASH state = stateDigitSlash
firstSlash = i firstSlash = i
} }
case st_DIGITDASH: // starts digit then dash 02- case stateDigitDash: // starts digit then dash 02-
// 2006-01-02T15:04:05Z07:00 // 2006-01-02T15:04:05Z07:00
// 2017-06-25T17:46:57.45706582-07:00 // 2017-06-25T17:46:57.45706582-07:00
// 2006-01-02T15:04:05.999999999Z07:00 // 2006-01-02T15:04:05.999999999Z07:00
@ -165,38 +165,38 @@ iterRunes:
// 2013-Feb-03 // 2013-Feb-03
switch { switch {
case r == ' ': case r == ' ':
state = st_DIGITDASHWS state = stateDigitDashWs
case r == 'T': case r == 'T':
state = st_DIGITDASHT state = stateDigitDashT
default: default:
if unicode.IsLetter(r) { if unicode.IsLetter(r) {
state = st_DIGITDASHALPHA state = stateDigitDashAlpha
break iterRunes break iterRunes
} }
} }
case st_DIGITDASHWS: case stateDigitDashWs:
// 2013-04-01 22:43:22 // 2013-04-01 22:43:22
// 2014-05-11 08:20:13,787 // 2014-05-11 08:20:13,787
// st_DIGITDASHWSWS // stateDigitDashWsWs
// 2014-04-26 05:24:37 PM // 2014-04-26 05:24:37 PM
// 2014-12-16 06:20:00 UTC // 2014-12-16 06:20:00 UTC
// 2015-02-18 00:12:00 +0000 UTC // 2015-02-18 00:12:00 +0000 UTC
// 2006-01-02 15:04:05 -0700 // 2006-01-02 15:04:05 -0700
// 2006-01-02 15:04:05 -07:00 // 2006-01-02 15:04:05 -07:00
// st_DIGITDASHWSOFFSET // stateDigitDashWsOffset
// 2017-07-19 03:21:51+00:00 // 2017-07-19 03:21:51+00:00
// st_DIGITDASHWSDOT // stateDigitDashWsPeriod
// 2014-04-26 17:24:37.3186369 // 2014-04-26 17:24:37.3186369
// 2017-01-27 00:07:31.945167 // 2017-01-27 00:07:31.945167
// 2012-08-03 18:31:59.257000000 // 2012-08-03 18:31:59.257000000
// 2016-03-14 00:00:00.000 // 2016-03-14 00:00:00.000
// st_DIGITDASHWSDOTOFFSET // stateDigitDashWsPeriodOffset
// 2017-01-27 00:07:31.945167 +0000 // 2017-01-27 00:07:31.945167 +0000
// 2016-03-14 00:00:00.000 +0000 // 2016-03-14 00:00:00.000 +0000
// st_DIGITDASHWSDOTOFFSETALPHA // stateDigitDashWsPeriodOffsetAlpha
// 2017-01-27 00:07:31.945167 +0000 UTC // 2017-01-27 00:07:31.945167 +0000 UTC
// 2016-03-14 00:00:00.000 +0000 UTC // 2016-03-14 00:00:00.000 +0000 UTC
// st_DIGITDASHWSDOTALPHA // stateDigitDashWsPeriodAlpha
// 2014-12-16 06:20:00.000 UTC // 2014-12-16 06:20:00.000 UTC
switch r { switch r {
case ',': case ',':
@ -212,110 +212,110 @@ iterRunes:
return t, err return t, err
} }
case '-', '+': case '-', '+':
state = st_DIGITDASHWSOFFSET state = stateDigitDashWsOffset
case '.': case '.':
state = st_DIGITDASHWSDOT state = stateDigitDashWsPeriod
case ' ': case ' ':
state = st_DIGITDASHWSWS state = stateDigitDashWsWs
} }
case st_DIGITDASHWSWS: case stateDigitDashWsWs:
// st_DIGITDASHWSWSALPHA // stateDigitDashWsWsAlpha
// 2014-12-16 06:20:00 UTC // 2014-12-16 06:20:00 UTC
// st_DIGITDASHWSWSAMPMMAYBE // stateDigitDashWsWsAMPMMaybe
// 2014-04-26 05:24:37 PM // 2014-04-26 05:24:37 PM
// st_DIGITDASHWSWSOFFSET // stateDigitDashWsWsOffset
// 2006-01-02 15:04:05 -0700 // 2006-01-02 15:04:05 -0700
// st_DIGITDASHWSWSOFFSETCOLON // stateDigitDashWsWsOffsetColon
// 2006-01-02 15:04:05 -07:00 // 2006-01-02 15:04:05 -07:00
// st_DIGITDASHWSWSOFFSETCOLONALPHA // stateDigitDashWsWsOffsetColonAlpha
// 2015-02-18 00:12:00 +00:00 UTC // 2015-02-18 00:12:00 +00:00 UTC
// st_DIGITDASHWSWSOFFSETALPHA // stateDigitDashWsWsOffsetAlpha
// 2015-02-18 00:12:00 +0000 UTC // 2015-02-18 00:12:00 +0000 UTC
switch r { switch r {
case 'A', 'P': case 'A', 'P':
state = st_DIGITDASHWSWSAMPMMAYBE state = stateDigitDashWsWsAMPMMaybe
case '+', '-': case '+', '-':
state = st_DIGITDASHWSWSOFFSET state = stateDigitDashWsWsOffset
default: default:
if unicode.IsLetter(r) { if unicode.IsLetter(r) {
// 2014-12-16 06:20:00 UTC // 2014-12-16 06:20:00 UTC
state = st_DIGITDASHWSWSALPHA state = stateDigitDashWsWsAlpha
break iterRunes break iterRunes
} }
} }
case st_DIGITDASHWSWSAMPMMAYBE: case stateDigitDashWsWsAMPMMaybe:
if r == 'M' { if r == 'M' {
return parse("2006-01-02 03:04:05 PM", datestr, loc) return parse("2006-01-02 03:04:05 PM", datestr, loc)
} }
state = st_DIGITDASHWSWSALPHA state = stateDigitDashWsWsAlpha
case st_DIGITDASHWSWSOFFSET: case stateDigitDashWsWsOffset:
// st_DIGITDASHWSWSOFFSET // stateDigitDashWsWsOffset
// 2006-01-02 15:04:05 -0700 // 2006-01-02 15:04:05 -0700
// st_DIGITDASHWSWSOFFSETCOLON // stateDigitDashWsWsOffsetColon
// 2006-01-02 15:04:05 -07:00 // 2006-01-02 15:04:05 -07:00
// st_DIGITDASHWSWSOFFSETCOLONALPHA // stateDigitDashWsWsOffsetColonAlpha
// 2015-02-18 00:12:00 +00:00 UTC // 2015-02-18 00:12:00 +00:00 UTC
// st_DIGITDASHWSWSOFFSETALPHA // stateDigitDashWsWsOffsetAlpha
// 2015-02-18 00:12:00 +0000 UTC // 2015-02-18 00:12:00 +0000 UTC
if r == ':' { if r == ':' {
state = st_DIGITDASHWSWSOFFSETCOLON state = stateDigitDashWsWsOffsetColon
} else if unicode.IsLetter(r) { } else if unicode.IsLetter(r) {
// 2015-02-18 00:12:00 +0000 UTC // 2015-02-18 00:12:00 +0000 UTC
state = st_DIGITDASHWSWSOFFSETALPHA state = stateDigitDashWsWsOffsetAlpha
break iterRunes break iterRunes
} }
case st_DIGITDASHWSWSOFFSETCOLON: case stateDigitDashWsWsOffsetColon:
// st_DIGITDASHWSWSOFFSETCOLON // stateDigitDashWsWsOffsetColon
// 2006-01-02 15:04:05 -07:00 // 2006-01-02 15:04:05 -07:00
// st_DIGITDASHWSWSOFFSETCOLONALPHA // stateDigitDashWsWsOffsetColonAlpha
// 2015-02-18 00:12:00 +00:00 UTC // 2015-02-18 00:12:00 +00:00 UTC
if unicode.IsLetter(r) { if unicode.IsLetter(r) {
// 2015-02-18 00:12:00 +00:00 UTC // 2015-02-18 00:12:00 +00:00 UTC
state = st_DIGITDASHWSWSOFFSETCOLONALPHA state = stateDigitDashWsWsOffsetColonAlpha
break iterRunes break iterRunes
} }
case st_DIGITDASHWSDOT: case stateDigitDashWsPeriod:
// 2014-04-26 17:24:37.3186369 // 2014-04-26 17:24:37.3186369
// 2017-01-27 00:07:31.945167 // 2017-01-27 00:07:31.945167
// 2012-08-03 18:31:59.257000000 // 2012-08-03 18:31:59.257000000
// 2016-03-14 00:00:00.000 // 2016-03-14 00:00:00.000
// st_DIGITDASHWSDOTOFFSET // stateDigitDashWsPeriodOffset
// 2017-01-27 00:07:31.945167 +0000 // 2017-01-27 00:07:31.945167 +0000
// 2016-03-14 00:00:00.000 +0000 // 2016-03-14 00:00:00.000 +0000
// st_DIGITDASHWSDOTOFFSETALPHA // stateDigitDashWsPeriodOffsetAlpha
// 2017-01-27 00:07:31.945167 +0000 UTC // 2017-01-27 00:07:31.945167 +0000 UTC
// 2016-03-14 00:00:00.000 +0000 UTC // 2016-03-14 00:00:00.000 +0000 UTC
// st_DIGITDASHWSDOTALPHA // stateDigitDashWsPeriodAlpha
// 2014-12-16 06:20:00.000 UTC // 2014-12-16 06:20:00.000 UTC
if unicode.IsLetter(r) { if unicode.IsLetter(r) {
// 2014-12-16 06:20:00.000 UTC // 2014-12-16 06:20:00.000 UTC
state = st_DIGITDASHWSDOTALPHA state = stateDigitDashWsPeriodAlpha
break iterRunes break iterRunes
} else if r == '+' || r == '-' { } else if r == '+' || r == '-' {
state = st_DIGITDASHWSDOTOFFSET state = stateDigitDashWsPeriodOffset
} }
case st_DIGITDASHWSDOTOFFSET: case stateDigitDashWsPeriodOffset:
// 2017-01-27 00:07:31.945167 +0000 // 2017-01-27 00:07:31.945167 +0000
// 2016-03-14 00:00:00.000 +0000 // 2016-03-14 00:00:00.000 +0000
// st_DIGITDASHWSDOTOFFSETALPHA // stateDigitDashWsPeriodOffsetAlpha
// 2017-01-27 00:07:31.945167 +0000 UTC // 2017-01-27 00:07:31.945167 +0000 UTC
// 2016-03-14 00:00:00.000 +0000 UTC // 2016-03-14 00:00:00.000 +0000 UTC
if unicode.IsLetter(r) { if unicode.IsLetter(r) {
// 2014-12-16 06:20:00.000 UTC // 2014-12-16 06:20:00.000 UTC
// 2017-01-27 00:07:31.945167 +0000 UTC // 2017-01-27 00:07:31.945167 +0000 UTC
// 2016-03-14 00:00:00.000 +0000 UTC // 2016-03-14 00:00:00.000 +0000 UTC
state = st_DIGITDASHWSDOTOFFSETALPHA state = stateDigitDashWsPeriodOffsetAlpha
break iterRunes break iterRunes
} }
case st_DIGITDASHT: // starts digit then dash 02- then T case stateDigitDashT: // starts digit then dash 02- then T
// st_DIGITDASHT // stateDigitDashT
// 2006-01-02T15:04:05 // 2006-01-02T15:04:05
// st_DIGITDASHTZ // stateDigitDashTZ
// 2006-01-02T15:04:05.999999999Z // 2006-01-02T15:04:05.999999999Z
// 2006-01-02T15:04:05.99999999Z // 2006-01-02T15:04:05.99999999Z
// 2006-01-02T15:04:05.9999999Z // 2006-01-02T15:04:05.9999999Z
@ -325,30 +325,30 @@ iterRunes:
// 2006-01-02T15:04:05.999Z // 2006-01-02T15:04:05.999Z
// 2006-01-02T15:04:05.99Z // 2006-01-02T15:04:05.99Z
// 2009-08-12T22:15Z // 2009-08-12T22:15Z
// st_DIGITDASHTZDIGIT // stateDigitDashTZDigit
// 2006-01-02T15:04:05.999999999Z07:00 // 2006-01-02T15:04:05.999999999Z07:00
// 2006-01-02T15:04:05Z07:00 // 2006-01-02T15:04:05Z07:00
// With another dash aka time-zone at end // With another dash aka time-zone at end
// st_DIGITDASHTDELTA // stateDigitDashTOffset
// st_DIGITDASHTDELTACOLON // stateDigitDashTOffsetColon
// 2017-06-25T17:46:57.45706582-07:00 // 2017-06-25T17:46:57.45706582-07:00
// 2017-06-25T17:46:57+04:00 // 2017-06-25T17:46:57+04:00
// 2006-01-02T15:04:05+0000 // 2006-01-02T15:04:05+0000
switch r { switch r {
case '-', '+': case '-', '+':
state = st_DIGITDASHTDELTA state = stateDigitDashTOffset
case 'Z': case 'Z':
state = st_DIGITDASHTZ state = stateDigitDashTZ
} }
case st_DIGITDASHTZ: case stateDigitDashTZ:
if unicode.IsDigit(r) { if unicode.IsDigit(r) {
state = st_DIGITDASHTZDIGIT state = stateDigitDashTZDigit
} }
case st_DIGITDASHTDELTA: case stateDigitDashTOffset:
if r == ':' { if r == ':' {
state = st_DIGITDASHTDELTACOLON state = stateDigitDashTOffsetColon
} }
case st_DIGITSLASH: // starts digit then slash 02/ case stateDigitSlash: // starts digit then slash 02/
// 2014/07/10 06:55:38.156283 // 2014/07/10 06:55:38.156283
// 03/19/2012 10:11:59 // 03/19/2012 10:11:59
// 04/2/2014 03:00:37 // 04/2/2014 03:00:37
@ -363,9 +363,9 @@ iterRunes:
} }
switch r { switch r {
case ' ': case ' ':
state = st_DIGITSLASHWS state = stateDigitSlashWS
} }
case st_DIGITSLASHWS: // starts digit then slash 02/ more digits/slashes then whitespace case stateDigitSlashWS: // starts digit then slash 02/ more digits/slashes then whitespace
// 2014/07/10 06:55:38.156283 // 2014/07/10 06:55:38.156283
// 03/19/2012 10:11:59 // 03/19/2012 10:11:59
// 04/2/2014 03:00:37 // 04/2/2014 03:00:37
@ -373,9 +373,9 @@ iterRunes:
// 4/8/2014 22:05 // 4/8/2014 22:05
switch r { switch r {
case ':': case ':':
state = st_DIGITSLASHWSCOLON state = stateDigitSlashWSColon
} }
case st_DIGITSLASHWSCOLON: // starts digit then slash 02/ more digits/slashes then whitespace case stateDigitSlashWSColon: // starts digit then slash 02/ more digits/slashes then whitespace
// 2014/07/10 06:55:38.156283 // 2014/07/10 06:55:38.156283
// 03/19/2012 10:11:59 // 03/19/2012 10:11:59
// 04/2/2014 03:00:37 // 04/2/2014 03:00:37
@ -384,11 +384,11 @@ iterRunes:
// 3/1/2012 10:11:59 AM // 3/1/2012 10:11:59 AM
switch r { switch r {
case ':': case ':':
state = st_DIGITSLASHWSCOLONCOLON state = stateDigitSlashWSColonColon
case 'A', 'P': case 'A', 'P':
state = st_DIGITSLASHWSCOLONAMPM state = stateDigitSlashWSColonAMPM
} }
case st_DIGITSLASHWSCOLONCOLON: // starts digit then slash 02/ more digits/slashes then whitespace case stateDigitSlashWSColonColon: // starts digit then slash 02/ more digits/slashes then whitespace
// 2014/07/10 06:55:38.156283 // 2014/07/10 06:55:38.156283
// 03/19/2012 10:11:59 // 03/19/2012 10:11:59
// 04/2/2014 03:00:37 // 04/2/2014 03:00:37
@ -397,9 +397,9 @@ iterRunes:
// 3/1/2012 10:11:59 AM // 3/1/2012 10:11:59 AM
switch r { switch r {
case 'A', 'P': case 'A', 'P':
state = st_DIGITSLASHWSCOLONCOLONAMPM state = stateDigitSlashWSColonColonAMPM
} }
case st_DIGITALPHA: case stateDigitAlpha:
// 12 Feb 2006, 19:17 // 12 Feb 2006, 19:17
// 12 Feb 2006, 19:17:22 // 12 Feb 2006, 19:17:22
switch { switch {
@ -408,87 +408,85 @@ iterRunes:
case len(datestr) == len("02 Jan 2006, 15:04:05"): case len(datestr) == len("02 Jan 2006, 15:04:05"):
return parse("02 Jan 2006, 15:04:05", datestr, loc) return parse("02 Jan 2006, 15:04:05", datestr, loc)
} }
case st_ALPHA: // starts alpha case stateAlpha: // starts alpha
// st_ALPHAWS // stateAlphaWS
// Mon Jan _2 15:04:05 2006 // Mon Jan _2 15:04:05 2006
// Mon Jan _2 15:04:05 MST 2006 // Mon Jan _2 15:04:05 MST 2006
// Mon Jan 02 15:04:05 -0700 2006 // Mon Jan 02 15:04:05 -0700 2006
// Mon Aug 10 15:44:11 UTC+0100 2015 // Mon Aug 10 15:44:11 UTC+0100 2015
// Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time) // Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)
// st_ALPHAWSDIGITCOMMA // stateAlphaWSDigitComma
// May 8, 2009 5:57:51 PM // May 8, 2009 5:57:51 PM
// //
// st_WEEKDAYCOMMA // stateWeekdayComma
// Monday, 02-Jan-06 15:04:05 MST // Monday, 02-Jan-06 15:04:05 MST
// st_WEEKDAYCOMMADELTA // stateWeekdayCommaOffset
// Monday, 02 Jan 2006 15:04:05 -0700 // Monday, 02 Jan 2006 15:04:05 -0700
// Monday, 02 Jan 2006 15:04:05 +0100 // Monday, 02 Jan 2006 15:04:05 +0100
// st_WEEKDAYABBREVCOMMA // stateWeekdayAbbrevComma
// Mon, 02-Jan-06 15:04:05 MST // Mon, 02-Jan-06 15:04:05 MST
// Mon, 02 Jan 2006 15:04:05 MST // Mon, 02 Jan 2006 15:04:05 MST
// st_WEEKDAYABBREVCOMMADELTA // stateWeekdayAbbrevCommaOffset
// Mon, 02 Jan 2006 15:04:05 -0700 // Mon, 02 Jan 2006 15:04:05 -0700
// Thu, 13 Jul 2017 08:58:40 +0100 // Thu, 13 Jul 2017 08:58:40 +0100
// st_WEEKDAYABBREVCOMMADELTAZONE // stateWeekdayAbbrevCommaOffsetZone
// Tue, 11 Jul 2017 16:28:13 +0200 (CEST) // Tue, 11 Jul 2017 16:28:13 +0200 (CEST)
switch { switch {
case unicode.IsLetter(r): case unicode.IsLetter(r):
continue continue
case r == ' ': case r == ' ':
state = st_ALPHAWS state = stateAlphaWS
case r == ',': case r == ',':
if i == 3 { if i == 3 {
state = st_WEEKDAYABBREVCOMMA state = stateWeekdayAbbrevComma
} else { } else {
state = st_WEEKDAYCOMMA state = stateWeekdayComma
} }
} }
case st_WEEKDAYCOMMA: // Starts alpha then comma case stateWeekdayComma: // Starts alpha then comma
// Mon, 02-Jan-06 15:04:05 MST // Mon, 02-Jan-06 15:04:05 MST
// Mon, 02 Jan 2006 15:04:05 MST // Mon, 02 Jan 2006 15:04:05 MST
// st_WEEKDAYCOMMADELTA // stateWeekdayCommaOffset
// Monday, 02 Jan 2006 15:04:05 -0700 // Monday, 02 Jan 2006 15:04:05 -0700
// Monday, 02 Jan 2006 15:04:05 +0100 // Monday, 02 Jan 2006 15:04:05 +0100
switch { switch {
case r == '-': case r == '-':
if i < 15 { if i < 15 {
return parse("Monday, 02-Jan-06 15:04:05 MST", datestr, loc) return parse("Monday, 02-Jan-06 15:04:05 MST", datestr, loc)
} else {
state = st_WEEKDAYCOMMADELTA
} }
state = stateWeekdayCommaOffset
case r == '+': case r == '+':
state = st_WEEKDAYCOMMADELTA state = stateWeekdayCommaOffset
} }
case st_WEEKDAYABBREVCOMMA: // Starts alpha then comma case stateWeekdayAbbrevComma: // Starts alpha then comma
// Mon, 02-Jan-06 15:04:05 MST // Mon, 02-Jan-06 15:04:05 MST
// Mon, 02 Jan 2006 15:04:05 MST // Mon, 02 Jan 2006 15:04:05 MST
// st_WEEKDAYABBREVCOMMADELTA // stateWeekdayAbbrevCommaOffset
// Mon, 02 Jan 2006 15:04:05 -0700 // Mon, 02 Jan 2006 15:04:05 -0700
// Thu, 13 Jul 2017 08:58:40 +0100 // Thu, 13 Jul 2017 08:58:40 +0100
// st_WEEKDAYABBREVCOMMADELTAZONE // stateWeekdayAbbrevCommaOffsetZone
// Tue, 11 Jul 2017 16:28:13 +0200 (CEST) // Tue, 11 Jul 2017 16:28:13 +0200 (CEST)
switch { switch {
case r == '-': case r == '-':
if i < 15 { if i < 15 {
return parse("Mon, 02-Jan-06 15:04:05 MST", datestr, loc) return parse("Mon, 02-Jan-06 15:04:05 MST", datestr, loc)
} else {
state = st_WEEKDAYABBREVCOMMADELTA
} }
state = stateWeekdayAbbrevCommaOffset
case r == '+': case r == '+':
state = st_WEEKDAYABBREVCOMMADELTA state = stateWeekdayAbbrevCommaOffset
} }
case st_WEEKDAYABBREVCOMMADELTA: case stateWeekdayAbbrevCommaOffset:
// st_WEEKDAYABBREVCOMMADELTA // stateWeekdayAbbrevCommaOffset
// Mon, 02 Jan 2006 15:04:05 -0700 // Mon, 02 Jan 2006 15:04:05 -0700
// Thu, 13 Jul 2017 08:58:40 +0100 // Thu, 13 Jul 2017 08:58:40 +0100
// st_WEEKDAYABBREVCOMMADELTAZONE // stateWeekdayAbbrevCommaOffsetZone
// Tue, 11 Jul 2017 16:28:13 +0200 (CEST) // Tue, 11 Jul 2017 16:28:13 +0200 (CEST)
if r == '(' { if r == '(' {
state = st_WEEKDAYABBREVCOMMADELTAZONE state = stateWeekdayAbbrevCommaOffsetZone
} }
case st_ALPHAWS: // Starts alpha then whitespace case stateAlphaWS: // Starts alpha then whitespace
// Mon Jan _2 15:04:05 2006 // Mon Jan _2 15:04:05 2006
// Mon Jan _2 15:04:05 MST 2006 // Mon Jan _2 15:04:05 MST 2006
// Mon Jan 02 15:04:05 -0700 2006 // Mon Jan 02 15:04:05 -0700 2006
@ -496,47 +494,47 @@ iterRunes:
// Mon Aug 10 15:44:11 UTC+0100 2015 // Mon Aug 10 15:44:11 UTC+0100 2015
switch { switch {
case unicode.IsLetter(r): case unicode.IsLetter(r):
state = st_ALPHAWSALPHA state = stateAlphaWSAlpha
case unicode.IsDigit(r): case unicode.IsDigit(r):
state = st_ALPHAWSDIGITCOMMA state = stateAlphaWSDigitComma
} }
case st_ALPHAWSDIGITCOMMA: // Starts Alpha, whitespace, digit, comma case stateAlphaWSDigitComma: // Starts Alpha, whitespace, digit, comma
// May 8, 2009 5:57:51 PM // May 8, 2009 5:57:51 PM
return parse("Jan 2, 2006 3:04:05 PM", datestr, loc) return parse("Jan 2, 2006 3:04:05 PM", datestr, loc)
case st_ALPHAWSALPHA: // Alpha, whitespace, alpha case stateAlphaWSAlpha: // Alpha, whitespace, alpha
// Mon Jan _2 15:04:05 2006 // Mon Jan _2 15:04:05 2006
// Mon Jan 02 15:04:05 -0700 2006 // Mon Jan 02 15:04:05 -0700 2006
// Mon Jan _2 15:04:05 MST 2006 // Mon Jan _2 15:04:05 MST 2006
// Mon Aug 10 15:44:11 UTC+0100 2015 // Mon Aug 10 15:44:11 UTC+0100 2015
// Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time) // Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)
if r == ':' { if r == ':' {
state = st_ALPHAWSALPHACOLON state = stateAlphaWSAlphaColon
} }
case st_ALPHAWSALPHACOLON: // Alpha, whitespace, alpha, : case stateAlphaWSAlphaColon: // Alpha, whitespace, alpha, :
// Mon Jan _2 15:04:05 2006 // Mon Jan _2 15:04:05 2006
// Mon Jan 02 15:04:05 -0700 2006 // Mon Jan 02 15:04:05 -0700 2006
// Mon Jan _2 15:04:05 MST 2006 // Mon Jan _2 15:04:05 MST 2006
// Mon Aug 10 15:44:11 UTC+0100 2015 // Mon Aug 10 15:44:11 UTC+0100 2015
// Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time) // Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)
if unicode.IsLetter(r) { if unicode.IsLetter(r) {
state = st_ALPHAWSALPHACOLONALPHA state = stateAlphaWSAlphaColonAlpha
} else if r == '-' || r == '+' { } else if r == '-' || r == '+' {
state = st_ALPHAWSALPHACOLONOFFSET state = stateAlphaWSAlphaColonOffset
} }
case st_ALPHAWSALPHACOLONALPHA: // Alpha, whitespace, alpha, :, alpha case stateAlphaWSAlphaColonAlpha: // Alpha, whitespace, alpha, :, alpha
// Mon Jan _2 15:04:05 MST 2006 // Mon Jan _2 15:04:05 MST 2006
// Mon Aug 10 15:44:11 UTC+0100 2015 // Mon Aug 10 15:44:11 UTC+0100 2015
// Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time) // Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)
if r == '+' { if r == '+' {
state = st_ALPHAWSALPHACOLONALPHAOFFSET state = stateAlphaWSAlphaColonAlphaOffset
} }
case st_ALPHAWSALPHACOLONALPHAOFFSET: // Alpha, whitespace, alpha, : , alpha, offset, ? case stateAlphaWSAlphaColonAlphaOffset: // Alpha, whitespace, alpha, : , alpha, offset, ?
// Mon Aug 10 15:44:11 UTC+0100 2015 // Mon Aug 10 15:44:11 UTC+0100 2015
// Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time) // Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)
if unicode.IsLetter(r) { if unicode.IsLetter(r) {
state = st_ALPHAWSALPHACOLONALPHAOFFSETALPHA state = stateAlphaWSAlphaColonAlphaOffsetAlpha
} }
default: default:
break iterRunes break iterRunes
@ -544,7 +542,7 @@ iterRunes:
} }
switch state { switch state {
case st_DIGIT: case stateDigit:
// unixy timestamps ish // unixy timestamps ish
// 1499979655583057426 nanoseconds // 1499979655583057426 nanoseconds
// 1499979795437000 micro-seconds // 1499979795437000 micro-seconds
@ -569,12 +567,11 @@ iterRunes:
return parse("20060102", datestr, loc) return parse("20060102", datestr, loc)
} else if len(datestr) == len("2014") { } else if len(datestr) == len("2014") {
return parse("2006", datestr, loc) return parse("2006", datestr, loc)
} else {
if secs, err := strconv.ParseInt(datestr, 10, 64); err == nil {
return time.Unix(secs, 0), nil
}
} }
case st_DIGITDASH: // starts digit then dash 02- if secs, err := strconv.ParseInt(datestr, 10, 64); err == nil {
return time.Unix(secs, 0), nil
}
case stateDigitDash: // starts digit then dash 02-
// 2006-01-02 // 2006-01-02
// 2006-01 // 2006-01
if len(datestr) == len("2014-04-26") { if len(datestr) == len("2014-04-26") {
@ -582,15 +579,15 @@ iterRunes:
} else if len(datestr) == len("2014-04") { } else if len(datestr) == len("2014-04") {
return parse("2006-01", datestr, loc) return parse("2006-01", datestr, loc)
} }
case st_DIGITDASHALPHA: case stateDigitDashAlpha:
// 2013-Feb-03 // 2013-Feb-03
return parse("2006-Jan-02", datestr, loc) return parse("2006-Jan-02", datestr, loc)
case st_DIGITDASHTDELTA: case stateDigitDashTOffset:
// 2006-01-02T15:04:05+0000 // 2006-01-02T15:04:05+0000
return parse("2006-01-02T15:04:05-0700", datestr, loc) return parse("2006-01-02T15:04:05-0700", datestr, loc)
case st_DIGITDASHTDELTACOLON: case stateDigitDashTOffsetColon:
// With another +/- time-zone at end // With another +/- time-zone at end
// 2006-01-02T15:04:05.999999999+07:00 // 2006-01-02T15:04:05.999999999+07:00
// 2006-01-02T15:04:05.999999999-07:00 // 2006-01-02T15:04:05.999999999-07:00
@ -602,12 +599,12 @@ iterRunes:
// 2006-01-02T15:04:05-07:00 // 2006-01-02T15:04:05-07:00
return parse("2006-01-02T15:04:05-07:00", datestr, loc) return parse("2006-01-02T15:04:05-07:00", datestr, loc)
case st_DIGITDASHT: // starts digit then dash 02- then T case stateDigitDashT: // starts digit then dash 02- then T
// 2006-01-02T15:04:05.999999 // 2006-01-02T15:04:05.999999
// 2006-01-02T15:04:05.999999 // 2006-01-02T15:04:05.999999
return parse("2006-01-02T15:04:05", datestr, loc) return parse("2006-01-02T15:04:05", datestr, loc)
case st_DIGITDASHTZDIGIT: case stateDigitDashTZDigit:
// With a time-zone at end after Z // With a time-zone at end after Z
// 2006-01-02T15:04:05.999999999Z07:00 // 2006-01-02T15:04:05.999999999Z07:00
// 2006-01-02T15:04:05Z07:00 // 2006-01-02T15:04:05Z07:00
@ -615,7 +612,7 @@ iterRunes:
// RFC3339Nano = "2006-01-02T15:04:05.999999999Z07:00" // RFC3339Nano = "2006-01-02T15:04:05.999999999Z07:00"
return time.Time{}, fmt.Errorf("RFC339 Dates may not contain both Z & Offset for %q see https://github.com/golang/go/issues/5294", datestr) return time.Time{}, fmt.Errorf("RFC339 Dates may not contain both Z & Offset for %q see https://github.com/golang/go/issues/5294", datestr)
case st_DIGITDASHTZ: // starts digit then dash 02- then T Then Z case stateDigitDashTZ: // starts digit then dash 02- then T Then Z
// 2006-01-02T15:04:05.999999999Z // 2006-01-02T15:04:05.999999999Z
// 2006-01-02T15:04:05.99999999Z // 2006-01-02T15:04:05.99999999Z
// 2006-01-02T15:04:05.9999999Z // 2006-01-02T15:04:05.9999999Z
@ -631,19 +628,19 @@ iterRunes:
default: default:
return parse("2006-01-02T15:04:05Z", datestr, loc) return parse("2006-01-02T15:04:05Z", datestr, loc)
} }
case st_DIGITDASHWS: // starts digit then dash 02- then whitespace 1 << 2 << 5 + 3 case stateDigitDashWs: // starts digit then dash 02- then whitespace 1 << 2 << 5 + 3
// 2013-04-01 22:43:22 // 2013-04-01 22:43:22
return parse("2006-01-02 15:04:05", datestr, loc) return parse("2006-01-02 15:04:05", datestr, loc)
case st_DIGITDASHWSWSOFFSET: case stateDigitDashWsWsOffset:
// 2006-01-02 15:04:05 -0700 // 2006-01-02 15:04:05 -0700
return parse("2006-01-02 15:04:05 -0700", datestr, loc) return parse("2006-01-02 15:04:05 -0700", datestr, loc)
case st_DIGITDASHWSWSOFFSETCOLON: case stateDigitDashWsWsOffsetColon:
// 2006-01-02 15:04:05 -07:00 // 2006-01-02 15:04:05 -07:00
return parse("2006-01-02 15:04:05 -07:00", datestr, loc) return parse("2006-01-02 15:04:05 -07:00", datestr, loc)
case st_DIGITDASHWSWSOFFSETALPHA: case stateDigitDashWsWsOffsetAlpha:
// 2015-02-18 00:12:00 +0000 UTC // 2015-02-18 00:12:00 +0000 UTC
t, err := parse("2006-01-02 15:04:05 -0700 UTC", datestr, loc) t, err := parse("2006-01-02 15:04:05 -0700 UTC", datestr, loc)
if err == nil { if err == nil {
@ -651,15 +648,15 @@ iterRunes:
} }
return parse("2006-01-02 15:04:05 +0000 GMT", datestr, loc) return parse("2006-01-02 15:04:05 +0000 GMT", datestr, loc)
case st_DIGITDASHWSWSOFFSETCOLONALPHA: case stateDigitDashWsWsOffsetColonAlpha:
// 2015-02-18 00:12:00 +00:00 UTC // 2015-02-18 00:12:00 +00:00 UTC
return parse("2006-01-02 15:04:05 -07:00 UTC", datestr, loc) return parse("2006-01-02 15:04:05 -07:00 UTC", datestr, loc)
case st_DIGITDASHWSOFFSET: case stateDigitDashWsOffset:
// 2017-07-19 03:21:51+00:00 // 2017-07-19 03:21:51+00:00
return parse("2006-01-02 15:04:05-07:00", datestr, loc) return parse("2006-01-02 15:04:05-07:00", datestr, loc)
case st_DIGITDASHWSWSALPHA: case stateDigitDashWsWsAlpha:
// 2014-12-16 06:20:00 UTC // 2014-12-16 06:20:00 UTC
t, err := parse("2006-01-02 15:04:05 UTC", datestr, loc) t, err := parse("2006-01-02 15:04:05 UTC", datestr, loc)
if err == nil { if err == nil {
@ -676,51 +673,51 @@ iterRunes:
} }
} }
case st_DIGITDASHWSDOT: case stateDigitDashWsPeriod:
// 2012-08-03 18:31:59.257000000 // 2012-08-03 18:31:59.257000000
// 2014-04-26 17:24:37.3186369 // 2014-04-26 17:24:37.3186369
// 2017-01-27 00:07:31.945167 // 2017-01-27 00:07:31.945167
// 2016-03-14 00:00:00.000 // 2016-03-14 00:00:00.000
return parse("2006-01-02 15:04:05", datestr, loc) return parse("2006-01-02 15:04:05", datestr, loc)
case st_DIGITDASHWSDOTALPHA: case stateDigitDashWsPeriodAlpha:
// 2012-08-03 18:31:59.257000000 UTC // 2012-08-03 18:31:59.257000000 UTC
// 2014-04-26 17:24:37.3186369 UTC // 2014-04-26 17:24:37.3186369 UTC
// 2017-01-27 00:07:31.945167 UTC // 2017-01-27 00:07:31.945167 UTC
// 2016-03-14 00:00:00.000 UTC // 2016-03-14 00:00:00.000 UTC
return parse("2006-01-02 15:04:05 UTC", datestr, loc) return parse("2006-01-02 15:04:05 UTC", datestr, loc)
case st_DIGITDASHWSDOTOFFSET: case stateDigitDashWsPeriodOffset:
// 2012-08-03 18:31:59.257000000 +0000 // 2012-08-03 18:31:59.257000000 +0000
// 2014-04-26 17:24:37.3186369 +0000 // 2014-04-26 17:24:37.3186369 +0000
// 2017-01-27 00:07:31.945167 +0000 // 2017-01-27 00:07:31.945167 +0000
// 2016-03-14 00:00:00.000 +0000 // 2016-03-14 00:00:00.000 +0000
return parse("2006-01-02 15:04:05 -0700", datestr, loc) return parse("2006-01-02 15:04:05 -0700", datestr, loc)
case st_DIGITDASHWSDOTOFFSETALPHA: case stateDigitDashWsPeriodOffsetAlpha:
// 2012-08-03 18:31:59.257000000 +0000 UTC // 2012-08-03 18:31:59.257000000 +0000 UTC
// 2014-04-26 17:24:37.3186369 +0000 UTC // 2014-04-26 17:24:37.3186369 +0000 UTC
// 2017-01-27 00:07:31.945167 +0000 UTC // 2017-01-27 00:07:31.945167 +0000 UTC
// 2016-03-14 00:00:00.000 +0000 UTC // 2016-03-14 00:00:00.000 +0000 UTC
return parse("2006-01-02 15:04:05 -0700 UTC", datestr, loc) return parse("2006-01-02 15:04:05 -0700 UTC", datestr, loc)
case st_ALPHAWSALPHACOLON: case stateAlphaWSAlphaColon:
// Mon Jan _2 15:04:05 2006 // Mon Jan _2 15:04:05 2006
return parse(time.ANSIC, datestr, loc) return parse(time.ANSIC, datestr, loc)
case st_ALPHAWSALPHACOLONOFFSET: case stateAlphaWSAlphaColonOffset:
// Mon Jan 02 15:04:05 -0700 2006 // Mon Jan 02 15:04:05 -0700 2006
return parse(time.RubyDate, datestr, loc) return parse(time.RubyDate, datestr, loc)
case st_ALPHAWSALPHACOLONALPHA: case stateAlphaWSAlphaColonAlpha:
// Mon Jan _2 15:04:05 MST 2006 // Mon Jan _2 15:04:05 MST 2006
return parse(time.UnixDate, datestr, loc) return parse(time.UnixDate, datestr, loc)
case st_ALPHAWSALPHACOLONALPHAOFFSET: case stateAlphaWSAlphaColonAlphaOffset:
// Mon Aug 10 15:44:11 UTC+0100 2015 // Mon Aug 10 15:44:11 UTC+0100 2015
return parse("Mon Jan 02 15:04:05 MST-0700 2006", datestr, loc) return parse("Mon Jan 02 15:04:05 MST-0700 2006", datestr, loc)
case st_ALPHAWSALPHACOLONALPHAOFFSETALPHA: case stateAlphaWSAlphaColonAlphaOffsetAlpha:
// Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time) // Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)
if len(datestr) > len("Mon Jan 02 2006 15:04:05 MST-0700") { if len(datestr) > len("Mon Jan 02 2006 15:04:05 MST-0700") {
// What effing time stamp is this? // What effing time stamp is this?
@ -728,7 +725,7 @@ iterRunes:
dateTmp := datestr[:33] dateTmp := datestr[:33]
return parse("Mon Jan 02 2006 15:04:05 MST-0700", dateTmp, loc) return parse("Mon Jan 02 2006 15:04:05 MST-0700", dateTmp, loc)
} }
case st_DIGITSLASH: // starts digit then slash 02/ (but nothing else) case stateDigitSlash: // starts digit then slash 02/ (but nothing else)
// 3/1/2014 // 3/1/2014
// 10/13/2014 // 10/13/2014
// 01/02/2006 // 01/02/2006
@ -736,9 +733,8 @@ iterRunes:
if firstSlash == 4 { if firstSlash == 4 {
if len(datestr) == len("2006/01/02") { if len(datestr) == len("2006/01/02") {
return parse("2006/01/02", datestr, loc) return parse("2006/01/02", datestr, loc)
} else {
return parse("2006/1/2", datestr, loc)
} }
return parse("2006/1/2", datestr, loc)
} else { } else {
for _, parseFormat := range shortDates { for _, parseFormat := range shortDates {
if t, err := parse(parseFormat, datestr, loc); err == nil { if t, err := parse(parseFormat, datestr, loc); err == nil {
@ -747,7 +743,7 @@ iterRunes:
} }
} }
case st_DIGITSLASHWSCOLON: // starts digit then slash 02/ more digits/slashes then whitespace case stateDigitSlashWSColon: // starts digit then slash 02/ more digits/slashes then whitespace
// 4/8/2014 22:05 // 4/8/2014 22:05
// 04/08/2014 22:05 // 04/08/2014 22:05
// 2014/4/8 22:05 // 2014/4/8 22:05
@ -767,7 +763,7 @@ iterRunes:
} }
} }
case st_DIGITSLASHWSCOLONAMPM: // starts digit then slash 02/ more digits/slashes then whitespace case stateDigitSlashWSColonAMPM: // starts digit then slash 02/ more digits/slashes then whitespace
// 4/8/2014 22:05 PM // 4/8/2014 22:05 PM
// 04/08/2014 22:05 PM // 04/08/2014 22:05 PM
// 04/08/2014 1:05 PM // 04/08/2014 1:05 PM
@ -791,7 +787,7 @@ iterRunes:
} }
} }
case st_DIGITSLASHWSCOLONCOLON: // starts digit then slash 02/ more digits/slashes then whitespace double colons case stateDigitSlashWSColonColon: // starts digit then slash 02/ more digits/slashes then whitespace double colons
// 2014/07/10 06:55:38.156283 // 2014/07/10 06:55:38.156283
// 03/19/2012 10:11:59 // 03/19/2012 10:11:59
// 3/1/2012 10:11:59 // 3/1/2012 10:11:59
@ -811,7 +807,7 @@ iterRunes:
} }
} }
case st_DIGITSLASHWSCOLONCOLONAMPM: // starts digit then slash 02/ more digits/slashes then whitespace double colons case stateDigitSlashWSColonColonAMPM: // starts digit then slash 02/ more digits/slashes then whitespace double colons
// 2014/07/10 06:55:38.156283 PM // 2014/07/10 06:55:38.156283 PM
// 03/19/2012 10:11:59 PM // 03/19/2012 10:11:59 PM
// 3/1/2012 10:11:59 PM // 3/1/2012 10:11:59 PM
@ -833,20 +829,20 @@ iterRunes:
} }
} }
case st_WEEKDAYCOMMADELTA: case stateWeekdayCommaOffset:
// Monday, 02 Jan 2006 15:04:05 -0700 // Monday, 02 Jan 2006 15:04:05 -0700
// Monday, 02 Jan 2006 15:04:05 +0100 // Monday, 02 Jan 2006 15:04:05 +0100
return parse("Monday, 02 Jan 2006 15:04:05 -0700", datestr, loc) return parse("Monday, 02 Jan 2006 15:04:05 -0700", datestr, loc)
case st_WEEKDAYABBREVCOMMA: // Starts alpha then comma case stateWeekdayAbbrevComma: // Starts alpha then comma
// Mon, 02-Jan-06 15:04:05 MST // Mon, 02-Jan-06 15:04:05 MST
// Mon, 02 Jan 2006 15:04:05 MST // Mon, 02 Jan 2006 15:04:05 MST
return parse("Mon, 02 Jan 2006 15:04:05 MST", datestr, loc) return parse("Mon, 02 Jan 2006 15:04:05 MST", datestr, loc)
case st_WEEKDAYABBREVCOMMADELTA: case stateWeekdayAbbrevCommaOffset:
// Mon, 02 Jan 2006 15:04:05 -0700 // Mon, 02 Jan 2006 15:04:05 -0700
// Thu, 13 Jul 2017 08:58:40 +0100 // Thu, 13 Jul 2017 08:58:40 +0100
// RFC1123Z = "Mon, 02 Jan 2006 15:04:05 -0700" // RFC1123 with numeric zone // RFC1123Z = "Mon, 02 Jan 2006 15:04:05 -0700" // RFC1123 with numeric zone
return parse("Mon, 02 Jan 2006 15:04:05 -0700", datestr, loc) return parse("Mon, 02 Jan 2006 15:04:05 -0700", datestr, loc)
case st_WEEKDAYABBREVCOMMADELTAZONE: case stateWeekdayAbbrevCommaOffsetZone:
// Tue, 11 Jul 2017 16:28:13 +0200 (CEST) // Tue, 11 Jul 2017 16:28:13 +0200 (CEST)
return parse("Mon, 02 Jan 2006 15:04:05 -0700 (CEST)", datestr, loc) return parse("Mon, 02 Jan 2006 15:04:05 -0700 (CEST)", datestr, loc)
} }

View File

@ -128,7 +128,7 @@ func TestParseInLocation(t *testing.T) {
// UnixDate = "Mon Jan _2 15:04:05 MST 2006" // UnixDate = "Mon Jan _2 15:04:05 MST 2006"
ts = MustParse("Mon Jan 2 15:04:05 MST 2006") ts = MustParse("Mon Jan 2 15:04:05 MST 2006")
zone, offset = ts.Zone() _, offset = ts.Zone()
assert.Equal(t, 0, offset, "Should have found offset = 0 %v", offset) assert.Equal(t, 0, offset, "Should have found offset = 0 %v", offset)
assert.Equal(t, "2006-01-02 15:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC))) assert.Equal(t, "2006-01-02 15:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))