mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-13 05:06:36 +08:00
date no year format
This commit is contained in:
parent
21df004e09
commit
7c404b68a4
18
parseany.go
18
parseany.go
@ -61,7 +61,7 @@ const (
|
|||||||
dateAlphaWsDigitMoreWs
|
dateAlphaWsDigitMoreWs
|
||||||
dateAlphaWsDigitMoreWsYear
|
dateAlphaWsDigitMoreWsYear
|
||||||
dateAlphaWsMonth
|
dateAlphaWsMonth
|
||||||
dateAlphaWsMonthMore
|
dateAlphaWsMonthMore // 25
|
||||||
dateAlphaWsMonthSuffix
|
dateAlphaWsMonthSuffix
|
||||||
dateAlphaWsMore
|
dateAlphaWsMore
|
||||||
dateAlphaWsAtTime
|
dateAlphaWsAtTime
|
||||||
@ -530,6 +530,7 @@ iterRunes:
|
|||||||
// 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)
|
||||||
|
// Jan 20 21:17:01
|
||||||
// dateAlphaWSDigit
|
// dateAlphaWSDigit
|
||||||
// May 8, 2009 5:57:51 PM
|
// May 8, 2009 5:57:51 PM
|
||||||
// oct 1, 1970
|
// oct 1, 1970
|
||||||
@ -624,6 +625,7 @@ iterRunes:
|
|||||||
// May 8 2009 5:57:51 PM
|
// May 8 2009 5:57:51 PM
|
||||||
// oct 1, 1970
|
// oct 1, 1970
|
||||||
// oct 7, '70
|
// oct 7, '70
|
||||||
|
// Jan 20 21:17:01
|
||||||
switch {
|
switch {
|
||||||
case unicode.IsLetter(r):
|
case unicode.IsLetter(r):
|
||||||
p.set(0, "Mon")
|
p.set(0, "Mon")
|
||||||
@ -641,6 +643,7 @@ iterRunes:
|
|||||||
// oct 1, 1970
|
// oct 1, 1970
|
||||||
// oct 7, '70
|
// oct 7, '70
|
||||||
// oct. 7, 1970
|
// oct. 7, 1970
|
||||||
|
// Jan 20 21:17:01
|
||||||
if r == ',' {
|
if r == ',' {
|
||||||
p.daylen = i - p.dayi
|
p.daylen = i - p.dayi
|
||||||
p.setDay()
|
p.setDay()
|
||||||
@ -671,9 +674,21 @@ iterRunes:
|
|||||||
// May 05, 2005, 05:05:05
|
// May 05, 2005, 05:05:05
|
||||||
// oct 1, 1970
|
// oct 1, 1970
|
||||||
// oct 7, '70
|
// oct 7, '70
|
||||||
|
// Jan 20 21:17:01
|
||||||
switch r {
|
switch r {
|
||||||
case '\'':
|
case '\'':
|
||||||
p.yeari = i + 1
|
p.yeari = i + 1
|
||||||
|
case ':':
|
||||||
|
// x
|
||||||
|
// Jan 20 21:17:01
|
||||||
|
p.stateTime = timeStart
|
||||||
|
p.dayi = i - 2
|
||||||
|
p.setDay()
|
||||||
|
i = i - 3
|
||||||
|
// this is a crap format, no year is in it which
|
||||||
|
// go will not parse. So, we have to do some ugly crap to create format.
|
||||||
|
datestr = fmt.Sprintf("%s %d %s", datestr[:i], time.Now().Year(), datestr[i:])
|
||||||
|
return parseTime(datestr, loc)
|
||||||
case ' ', ',':
|
case ' ', ',':
|
||||||
// x
|
// x
|
||||||
// May 8, 2009 5:57:51 PM
|
// May 8, 2009 5:57:51 PM
|
||||||
@ -685,7 +700,6 @@ iterRunes:
|
|||||||
p.stateTime = timeStart
|
p.stateTime = timeStart
|
||||||
break iterRunes
|
break iterRunes
|
||||||
}
|
}
|
||||||
|
|
||||||
case dateAlphaWsAlpha:
|
case dateAlphaWsAlpha:
|
||||||
// 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
|
||||||
|
@ -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("Jan 20 21:17:01")
|
||||||
assert.Equal(t, "2012-09-17 10:10:09 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
assert.Equal(t, "2019-01-20 21:17:01 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
}
|
}
|
||||||
|
|
||||||
type dateTest struct {
|
type dateTest struct {
|
||||||
@ -88,6 +88,8 @@ var testInputs = []dateTest{
|
|||||||
{in: "May 7, 2012", out: "2012-05-07 00:00:00 +0000 UTC"},
|
{in: "May 7, 2012", out: "2012-05-07 00:00:00 +0000 UTC"},
|
||||||
{in: "June 7, 2012", out: "2012-06-07 00:00:00 +0000 UTC"},
|
{in: "June 7, 2012", out: "2012-06-07 00:00:00 +0000 UTC"},
|
||||||
{in: "June 7 2012", out: "2012-06-07 00:00:00 +0000 UTC"},
|
{in: "June 7 2012", out: "2012-06-07 00:00:00 +0000 UTC"},
|
||||||
|
// Mon dd hh:mm.ss
|
||||||
|
{in: "Sep 17 15:01:00", out: fmt.Sprintf("%d-09-17 15:01:00 +0000 UTC", time.Now().Year())},
|
||||||
// Month dd[th,nd,st,rd] yyyy
|
// Month dd[th,nd,st,rd] yyyy
|
||||||
{in: "September 17th, 2012", out: "2012-09-17 00:00:00 +0000 UTC"},
|
{in: "September 17th, 2012", out: "2012-09-17 00:00:00 +0000 UTC"},
|
||||||
{in: "September 17th 2012", out: "2012-09-17 00:00:00 +0000 UTC"},
|
{in: "September 17th 2012", out: "2012-09-17 00:00:00 +0000 UTC"},
|
||||||
|
Loading…
Reference in New Issue
Block a user