From cadc8ad72d86d48892cc989919b62616d86947dc Mon Sep 17 00:00:00 2001 From: emacsist Date: Sat, 12 Nov 2016 02:01:40 +0800 Subject: [PATCH] add "yyyy-MM-dd HH:mm:ss" string format > time.Time I notice that the Hugo use this project to convert the string to time.Time. When I migrate to Hugo from Hexo (another static blog generator). The Hugo said : > page.go:750: Failed to parse date '2016-03-06 15:28:01' in page xxxxx.md I hope you can merge this Pull request, so that those people who migrate to Hugo from Hexo are easy to use Hugo to generate the static blog. Thanks. --- cast_test.go | 6 ++++++ caste.go | 1 + 2 files changed, 7 insertions(+) diff --git a/cast_test.go b/cast_test.go index 6b73ff8..16e98d6 100644 --- a/cast_test.go +++ b/cast_test.go @@ -212,3 +212,9 @@ func TestToDuration(t *testing.T) { assert.Equal(t, v.expected, ToDuration(v.input)) } } + +func TestStringToDate(t *testing.T) { + dateString := "2016-12-01 15:05:04" + tv, _ := time.Parse("2006-01-02 15:04:05", dateString) + assert.Equal(t, ToTime(dateString), tv) +} diff --git a/caste.go b/caste.go index 23f59a1..23f0fe8 100644 --- a/caste.go +++ b/caste.go @@ -513,6 +513,7 @@ func StringToDate(s string) (time.Time, error) { "02 Jan 2006", "2006-01-02 15:04:05 -07:00", "2006-01-02 15:04:05 -0700", + "2006-01-02 15:04:05", }) }