mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-10 11:51:54 +08:00
New date format
This commit is contained in:
parent
5051e9281e
commit
2943ab2f5b
@ -54,6 +54,7 @@ var examples = []string{
|
|||||||
"2009-08-12T22:15:09Z",
|
"2009-08-12T22:15:09Z",
|
||||||
"2009-08-12T22:15:09",
|
"2009-08-12T22:15:09",
|
||||||
"2014-04-26 17:24:37.3186369",
|
"2014-04-26 17:24:37.3186369",
|
||||||
|
"2014-04-26 17:24:37.318636",
|
||||||
"2012-08-03 18:31:59.257000000 +0000 UTC",
|
"2012-08-03 18:31:59.257000000 +0000 UTC",
|
||||||
"2015-09-30 18:48:56.35272715 +0000 UTC",
|
"2015-09-30 18:48:56.35272715 +0000 UTC",
|
||||||
"2012-08-03 18:31:59.257000000",
|
"2012-08-03 18:31:59.257000000",
|
||||||
|
@ -44,6 +44,7 @@ var examples = []string{
|
|||||||
"2009-08-12T22:15:09Z",
|
"2009-08-12T22:15:09Z",
|
||||||
"2009-08-12T22:15:09",
|
"2009-08-12T22:15:09",
|
||||||
"2014-04-26 17:24:37.3186369",
|
"2014-04-26 17:24:37.3186369",
|
||||||
|
"2014-04-26 17:24:37.318636",
|
||||||
"2012-08-03 18:31:59.257000000 +0000 UTC",
|
"2012-08-03 18:31:59.257000000 +0000 UTC",
|
||||||
"2015-09-30 18:48:56.35272715 +0000 UTC",
|
"2015-09-30 18:48:56.35272715 +0000 UTC",
|
||||||
"2012-08-03 18:31:59.257000000",
|
"2012-08-03 18:31:59.257000000",
|
||||||
@ -115,6 +116,7 @@ func main() {
|
|||||||
| 2009-08-12T22:15:09Z | 2009-08-12 22:15:09 +0000 UTC |
|
| 2009-08-12T22:15:09Z | 2009-08-12 22:15:09 +0000 UTC |
|
||||||
| 2009-08-12T22:15:09 | 2009-08-12 22:15:09 +0000 UTC |
|
| 2009-08-12T22:15:09 | 2009-08-12 22:15:09 +0000 UTC |
|
||||||
| 2014-04-26 17:24:37.3186369 | 2014-04-26 17:24:37.3186369 +0000 UTC |
|
| 2014-04-26 17:24:37.3186369 | 2014-04-26 17:24:37.3186369 +0000 UTC |
|
||||||
|
| 2014-04-26 17:24:37.318636 | 2014-04-26 17:24:37.318636 +0000 UTC |
|
||||||
| 2012-08-03 18:31:59.257000000 +0000 UTC | 2012-08-03 18:31:59.257 +0000 UTC |
|
| 2012-08-03 18:31:59.257000000 +0000 UTC | 2012-08-03 18:31:59.257 +0000 UTC |
|
||||||
| 2015-09-30 18:48:56.35272715 +0000 UTC | 2015-09-30 18:48:56.35272715 +0000 UTC |
|
| 2015-09-30 18:48:56.35272715 +0000 UTC | 2015-09-30 18:48:56.35272715 +0000 UTC |
|
||||||
| 2012-08-03 18:31:59.257000000 | 2012-08-03 18:31:59.257 +0000 UTC |
|
| 2012-08-03 18:31:59.257000000 | 2012-08-03 18:31:59.257 +0000 UTC |
|
||||||
|
11
parseany.go
11
parseany.go
@ -102,6 +102,7 @@ iterRunes:
|
|||||||
// 2006-01-02T15:04:05.999999999Z07:00
|
// 2006-01-02T15:04:05.999999999Z07:00
|
||||||
// 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
|
||||||
// 2016-03-14 00:00:00.000
|
// 2016-03-14 00:00:00.000
|
||||||
// 2014-05-11 08:20:13,787
|
// 2014-05-11 08:20:13,787
|
||||||
// 2006-01-02
|
// 2006-01-02
|
||||||
@ -115,6 +116,7 @@ iterRunes:
|
|||||||
}
|
}
|
||||||
case ST_DIGITDASHWS: // starts digit then dash 02- then whitespace
|
case ST_DIGITDASHWS: // starts digit then dash 02- then whitespace
|
||||||
// 2014-04-26 17:24:37.3186369
|
// 2014-04-26 17:24:37.3186369
|
||||||
|
// 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
|
||||||
// 2013-04-01 22:43:22
|
// 2013-04-01 22:43:22
|
||||||
@ -468,8 +470,9 @@ iterRunes:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case ST_DIGITDASHWS: // starts digit then dash 02- then whitespace 1 << 2 << 5 + 3
|
case ST_DIGITDASHWS: // starts digit then dash 02- then whitespace 1 << 2 << 5 + 3
|
||||||
// 2014-04-26 17:24:37.3186369
|
|
||||||
// 2012-08-03 18:31:59.257000000
|
// 2012-08-03 18:31:59.257000000
|
||||||
|
// 2014-04-26 17:24:37.3186369
|
||||||
|
// 2017-01-27 00:07:31.945167
|
||||||
// 2016-03-14 00:00:00.000
|
// 2016-03-14 00:00:00.000
|
||||||
// 2013-04-01 22:43:22
|
// 2013-04-01 22:43:22
|
||||||
if len(datestr) == len("2012-08-03 18:31:59.257000000") {
|
if len(datestr) == len("2012-08-03 18:31:59.257000000") {
|
||||||
@ -484,6 +487,12 @@ iterRunes:
|
|||||||
} else {
|
} else {
|
||||||
return time.Time{}, err
|
return time.Time{}, err
|
||||||
}
|
}
|
||||||
|
} else if len(datestr) == len("2014-04-26 05:24:37.945167") {
|
||||||
|
if t, err := time.Parse("2006-01-02 15:04:05.000000", datestr); err == nil {
|
||||||
|
return t, nil
|
||||||
|
} else {
|
||||||
|
return time.Time{}, err
|
||||||
|
}
|
||||||
} else if len(datestr) == len("2014-04-26 05:24:37.000") {
|
} else if len(datestr) == len("2014-04-26 05:24:37.000") {
|
||||||
if t, err := time.Parse("2006-01-02 15:04:05.000", datestr); err == nil {
|
if t, err := time.Parse("2006-01-02 15:04:05.000", datestr); err == nil {
|
||||||
return t, nil
|
return t, nil
|
||||||
|
@ -261,6 +261,11 @@ func TestParse(t *testing.T) {
|
|||||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||||
assert.T(t, "2015-09-30 18:48:56.35272715 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
assert.T(t, "2015-09-30 18:48:56.35272715 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
|
|
||||||
|
ts, err = ParseAny("2017-01-27 00:07:31.945167")
|
||||||
|
assert.Tf(t, err == nil, "%v", err)
|
||||||
|
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||||
|
assert.T(t, "2017-01-27 00:07:31.945167 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
|
|
||||||
ts, err = ParseAny("2012-08-03 18:31:59.257000000")
|
ts, err = ParseAny("2012-08-03 18:31:59.257000000")
|
||||||
assert.Tf(t, err == nil, "%v", err)
|
assert.Tf(t, err == nil, "%v", err)
|
||||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||||
|
Loading…
Reference in New Issue
Block a user