new format closes #76

This commit is contained in:
Aaron Raddon 2019-02-22 16:50:43 -08:00
parent 21df004e09
commit c4a7a0dec4
4 changed files with 38 additions and 10 deletions

View File

@ -68,13 +68,17 @@ var examples = []string{
"Thu, 4 Jan 2018 17:53:36 +0000", "Thu, 4 Jan 2018 17:53:36 +0000",
"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)",
"September 17, 2012 10:09am",
"September 17, 2012 at 10:09am PST-08", "September 17, 2012 at 10:09am PST-08",
"September 17, 2012, 10:10:09",
"October 7, 1970", "October 7, 1970",
"October 7th, 1970",
"12 Feb 2006, 19:17", "12 Feb 2006, 19:17",
"12 Feb 2006 19:17", "12 Feb 2006 19:17",
"7 oct 70", "7 oct 70",
"7 oct 1970", "7 oct 1970",
"03 February 2013", "03 February 2013",
"1 July 2013",
"2013-Feb-03", "2013-Feb-03",
// mm/dd/yy // mm/dd/yy
"3/31/2014", "3/31/2014",
@ -137,6 +141,7 @@ var examples = []string{
"03.31.2014", "03.31.2014",
"08.21.71", "08.21.71",
"2014.03", "2014.03",
"2014.03.30",
// yyyymmdd and similar // yyyymmdd and similar
"20140601", "20140601",
"20140722105203", "20140722105203",
@ -264,6 +269,7 @@ func main() {
| 03.31.2014 | 2014-03-31 00:00:00 +0000 UTC | | 03.31.2014 | 2014-03-31 00:00:00 +0000 UTC |
| 08.21.71 | 1971-08-21 00:00:00 +0000 UTC | | 08.21.71 | 1971-08-21 00:00:00 +0000 UTC |
| 2014.03 | 2014-03-01 00:00:00 +0000 UTC | | 2014.03 | 2014-03-01 00:00:00 +0000 UTC |
| 2014.03.30 | 2014-03-30 00:00:00 +0000 UTC |
| 20140601 | 2014-06-01 00:00:00 +0000 UTC | | 20140601 | 2014-06-01 00:00:00 +0000 UTC |
| 20140722105203 | 2014-07-22 10:52:03 +0000 UTC | | 20140722105203 | 2014-07-22 10:52:03 +0000 UTC |
| 1332151919 | 2012-03-19 10:11:59 +0000 UTC | | 1332151919 | 2012-03-19 10:11:59 +0000 UTC |

View File

@ -98,6 +98,7 @@ var examples = []string{
"03.31.2014", "03.31.2014",
"08.21.71", "08.21.71",
"2014.03", "2014.03",
"2014.03.30",
// yyyymmdd and similar // yyyymmdd and similar
"20140601", "20140601",
"20140722105203", "20140722105203",
@ -225,6 +226,7 @@ func main() {
| 03.31.2014 | 2014-03-31 00:00:00 +0000 UTC | | 03.31.2014 | 2014-03-31 00:00:00 +0000 UTC |
| 08.21.71 | 1971-08-21 00:00:00 +0000 UTC | | 08.21.71 | 1971-08-21 00:00:00 +0000 UTC |
| 2014.03 | 2014-03-01 00:00:00 +0000 UTC | | 2014.03 | 2014-03-01 00:00:00 +0000 UTC |
| 2014.03.30 | 2014-03-30 00:00:00 +0000 UTC |
| 20140601 | 2014-06-01 00:00:00 +0000 UTC | | 20140601 | 2014-06-01 00:00:00 +0000 UTC |
| 20140722105203 | 2014-07-22 10:52:03 +0000 UTC | | 20140722105203 | 2014-07-22 10:52:03 +0000 UTC |
| 1332151919 | 2012-03-19 10:11:59 +0000 UTC | | 1332151919 | 2012-03-19 10:11:59 +0000 UTC |
@ -232,5 +234,4 @@ func main() {
| 1384216367111222 | 2013-11-12 00:32:47.111222 +0000 UTC | | 1384216367111222 | 2013-11-12 00:32:47.111222 +0000 UTC |
| 1384216367111222333 | 2013-11-12 00:32:47.111222333 +0000 UTC | | 1384216367111222333 | 2013-11-12 00:32:47.111222333 +0000 UTC |
+-------------------------------------------------------+-----------------------------------------+ +-------------------------------------------------------+-----------------------------------------+
*/ */

View File

@ -512,14 +512,26 @@ iterRunes:
break break
} }
case dateDigitDot: case dateDigitDot:
// This is the 2nd period
// 3.31.2014 // 3.31.2014
// 08.21.71 // 08.21.71
// 2014.05 // 2014.05
// 2018.09.30
if r == '.' { if r == '.' {
p.daylen = i - p.dayi if p.moi == 0 {
p.yeari = i + 1 // 3.31.2014
p.setDay() p.daylen = i - p.dayi
p.stateDate = dateDigitDotDot p.yeari = i + 1
p.setDay()
p.stateDate = dateDigitDotDot
} else {
// 2018.09.30
//p.molen = 2
p.molen = i - p.moi
p.dayi = i + 1
p.setMonth()
p.stateDate = dateDigitDotDot
}
} }
case dateDigitDotDot: case dateDigitDotDot:
// iterate all the way through // iterate all the way through
@ -1553,8 +1565,15 @@ iterRunes:
// 3.2.1981 // 3.2.1981
// 3.2.81 // 3.2.81
// 08.21.71 // 08.21.71
p.setYear() // 2018.09.30
p.yearlen = i - p.yeari if p.yearlen > 0 {
// 2018.09.30
p.daylen = i - p.dayi
p.setDay()
} else {
p.setYear()
p.yearlen = i - p.yeari
}
return p, nil return p, nil
case dateDigitWsMoYear: case dateDigitWsMoYear:
@ -1815,7 +1834,7 @@ func (p *parser) parse() (time.Time, error) {
p.format = p.format[p.skip:] p.format = p.format[p.skip:]
p.datestr = p.datestr[p.skip:] p.datestr = p.datestr[p.skip:]
} }
//gou.Debugf("parse %q AS %s", p.datestr, string(p.format)) //gou.Debugf("parse %q AS %q", p.datestr, string(p.format))
if p.loc == nil { if p.loc == nil {
return time.Parse(string(p.format), p.datestr) return time.Parse(string(p.format), p.datestr)
} }

View File

@ -11,8 +11,8 @@ import (
func TestOne(t *testing.T) { func TestOne(t *testing.T) {
time.Local = time.UTC time.Local = time.UTC
var ts time.Time var ts time.Time
ts = MustParse("September 17, 2012, 10:10:09") ts = MustParse("2018.09.30")
assert.Equal(t, "2012-09-17 10:10:09 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC))) assert.Equal(t, "2018-09-30 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
} }
type dateTest struct { type dateTest struct {
@ -354,6 +354,8 @@ var testInputs = []dateTest{
{in: "2009-08-12T22:15:9.99999999Z", out: "2009-08-12 22:15:09.99999999 +0000 UTC"}, {in: "2009-08-12T22:15:9.99999999Z", out: "2009-08-12 22:15:09.99999999 +0000 UTC"},
// yyyy.mm // yyyy.mm
{in: "2014.05", out: "2014-05-01 00:00:00 +0000 UTC"}, {in: "2014.05", out: "2014-05-01 00:00:00 +0000 UTC"},
{in: "2018.09.30", out: "2018-09-30 00:00:00 +0000 UTC"},
// mm.dd.yyyy // mm.dd.yyyy
{in: "3.31.2014", out: "2014-03-31 00:00:00 +0000 UTC"}, {in: "3.31.2014", out: "2014-03-31 00:00:00 +0000 UTC"},
{in: "3.3.2014", out: "2014-03-03 00:00:00 +0000 UTC"}, {in: "3.3.2014", out: "2014-03-03 00:00:00 +0000 UTC"},