From 950255ef57b8938fbdb606cd2027229c39f7d7a2 Mon Sep 17 00:00:00 2001 From: shockerli Date: Thu, 27 Oct 2022 22:42:48 +0800 Subject: [PATCH] add support date int format eg: "20221025", "20221025010203" --- time.go | 2 ++ time_test.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/time.go b/time.go index 112d9bc..bf2c692 100644 --- a/time.go +++ b/time.go @@ -114,6 +114,8 @@ var timeFormats = []string{ "2006-01-02 15:04:05.999999999 -0700 MST", // Time.String() "2006-01-02", "02 Jan 2006", + "20060102", // date of int + "20060102150405", // datetime of int "2006-01-02T15:04:05-0700", // RFC3339 without timezone hh:mm colon "2006-01-02 15:04:05 -07:00", "2006-01-02 15:04:05 -0700", diff --git a/time_test.go b/time_test.go index 0b4c144..af5bc2c 100644 --- a/time_test.go +++ b/time_test.go @@ -168,6 +168,8 @@ func TestTimeE(t *testing.T) { {"2016-03-06 15:28:01-00:00", time.Date(2016, 3, 6, 15, 28, 1, 0, cvt.TimeLocation), false}, // RFC3339 without T {"2016-03-06 15:28:01-0000", time.Date(2016, 3, 6, 15, 28, 1, 0, cvt.TimeLocation), false}, // RFC3339 without T or timezone hh:mm colon + {"20090213", time.Date(2009, 2, 13, 0, 0, 0, 0, cvt.TimeLocation), false}, + {"20090213233130", time.Date(2009, 2, 13, 23, 31, 30, 0, cvt.TimeLocation), false}, {"Fri Sep 25 13:58:21 2016 -0400", time.Date(2016, 9, 25, 17, 58, 21, 0, cvt.TimeLocation), false}, {"13 Feb 2009", expect2, false}, {"2009-02-13", expect2, false},