Skip to content

Commit c4a7a0d

Browse files
author
Aaron Raddon
committed
new format closes #76
1 parent 21df004 commit c4a7a0d

4 files changed

Lines changed: 38 additions & 10 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,17 @@ var examples = []string{
6868
"Thu, 4 Jan 2018 17:53:36 +0000",
6969
"Mon Aug 10 15:44:11 UTC+0100 2015",
7070
"Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)",
71+
"September 17, 2012 10:09am",
7172
"September 17, 2012 at 10:09am PST-08",
73+
"September 17, 2012, 10:10:09",
7274
"October 7, 1970",
75+
"October 7th, 1970",
7376
"12 Feb 2006, 19:17",
7477
"12 Feb 2006 19:17",
7578
"7 oct 70",
7679
"7 oct 1970",
7780
"03 February 2013",
81+
"1 July 2013",
7882
"2013-Feb-03",
7983
// mm/dd/yy
8084
"3/31/2014",
@@ -137,6 +141,7 @@ var examples = []string{
137141
"03.31.2014",
138142
"08.21.71",
139143
"2014.03",
144+
"2014.03.30",
140145
// yyyymmdd and similar
141146
"20140601",
142147
"20140722105203",
@@ -264,6 +269,7 @@ func main() {
264269
| 03.31.2014 | 2014-03-31 00:00:00 +0000 UTC |
265270
| 08.21.71 | 1971-08-21 00:00:00 +0000 UTC |
266271
| 2014.03 | 2014-03-01 00:00:00 +0000 UTC |
272+
| 2014.03.30 | 2014-03-30 00:00:00 +0000 UTC |
267273
| 20140601 | 2014-06-01 00:00:00 +0000 UTC |
268274
| 20140722105203 | 2014-07-22 10:52:03 +0000 UTC |
269275
| 1332151919 | 2012-03-19 10:11:59 +0000 UTC |

example/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ var examples = []string{
9898
"03.31.2014",
9999
"08.21.71",
100100
"2014.03",
101+
"2014.03.30",
101102
// yyyymmdd and similar
102103
"20140601",
103104
"20140722105203",
@@ -225,12 +226,12 @@ func main() {
225226
| 03.31.2014 | 2014-03-31 00:00:00 +0000 UTC |
226227
| 08.21.71 | 1971-08-21 00:00:00 +0000 UTC |
227228
| 2014.03 | 2014-03-01 00:00:00 +0000 UTC |
229+
| 2014.03.30 | 2014-03-30 00:00:00 +0000 UTC |
228230
| 20140601 | 2014-06-01 00:00:00 +0000 UTC |
229231
| 20140722105203 | 2014-07-22 10:52:03 +0000 UTC |
230232
| 1332151919 | 2012-03-19 10:11:59 +0000 UTC |
231233
| 1384216367189 | 2013-11-12 00:32:47.189 +0000 UTC |
232234
| 1384216367111222 | 2013-11-12 00:32:47.111222 +0000 UTC |
233235
| 1384216367111222333 | 2013-11-12 00:32:47.111222333 +0000 UTC |
234236
+-------------------------------------------------------+-----------------------------------------+
235-
236237
*/

parseany.go

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -512,14 +512,26 @@ iterRunes:
512512
break
513513
}
514514
case dateDigitDot:
515+
// This is the 2nd period
515516
// 3.31.2014
516517
// 08.21.71
517518
// 2014.05
519+
// 2018.09.30
518520
if r == '.' {
519-
p.daylen = i - p.dayi
520-
p.yeari = i + 1
521-
p.setDay()
522-
p.stateDate = dateDigitDotDot
521+
if p.moi == 0 {
522+
// 3.31.2014
523+
p.daylen = i - p.dayi
524+
p.yeari = i + 1
525+
p.setDay()
526+
p.stateDate = dateDigitDotDot
527+
} else {
528+
// 2018.09.30
529+
//p.molen = 2
530+
p.molen = i - p.moi
531+
p.dayi = i + 1
532+
p.setMonth()
533+
p.stateDate = dateDigitDotDot
534+
}
523535
}
524536
case dateDigitDotDot:
525537
// iterate all the way through
@@ -1553,8 +1565,15 @@ iterRunes:
15531565
// 3.2.1981
15541566
// 3.2.81
15551567
// 08.21.71
1556-
p.setYear()
1557-
p.yearlen = i - p.yeari
1568+
// 2018.09.30
1569+
if p.yearlen > 0 {
1570+
// 2018.09.30
1571+
p.daylen = i - p.dayi
1572+
p.setDay()
1573+
} else {
1574+
p.setYear()
1575+
p.yearlen = i - p.yeari
1576+
}
15581577
return p, nil
15591578

15601579
case dateDigitWsMoYear:
@@ -1815,7 +1834,7 @@ func (p *parser) parse() (time.Time, error) {
18151834
p.format = p.format[p.skip:]
18161835
p.datestr = p.datestr[p.skip:]
18171836
}
1818-
//gou.Debugf("parse %q AS %s", p.datestr, string(p.format))
1837+
//gou.Debugf("parse %q AS %q", p.datestr, string(p.format))
18191838
if p.loc == nil {
18201839
return time.Parse(string(p.format), p.datestr)
18211840
}

parseany_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
func TestOne(t *testing.T) {
1212
time.Local = time.UTC
1313
var ts time.Time
14-
ts = MustParse("September 17, 2012, 10:10:09")
15-
assert.Equal(t, "2012-09-17 10:10:09 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
14+
ts = MustParse("2018.09.30")
15+
assert.Equal(t, "2018-09-30 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
1616
}
1717

1818
type dateTest struct {
@@ -354,6 +354,8 @@ var testInputs = []dateTest{
354354
{in: "2009-08-12T22:15:9.99999999Z", out: "2009-08-12 22:15:09.99999999 +0000 UTC"},
355355
// yyyy.mm
356356
{in: "2014.05", out: "2014-05-01 00:00:00 +0000 UTC"},
357+
{in: "2018.09.30", out: "2018-09-30 00:00:00 +0000 UTC"},
358+
357359
// mm.dd.yyyy
358360
{in: "3.31.2014", out: "2014-03-31 00:00:00 +0000 UTC"},
359361
{in: "3.3.2014", out: "2014-03-03 00:00:00 +0000 UTC"},

0 commit comments

Comments
 (0)