diff --git a/hugolib/helpers.go b/hugolib/helpers.go index 0bf0fa32a..b2eb39673 100644 --- a/hugolib/helpers.go +++ b/hugolib/helpers.go @@ -74,6 +74,10 @@ func interfaceToStringToDate(i interface{}) time.Time { time.ANSIC, time.UnixDate, time.RubyDate, + "2006-01-02 15:04:05Z07:00", + "02 Jan 06 15:04 MST", + "2006-01-02", + "02 Jan 2006", }); e == nil { return d } diff --git a/hugolib/page_time_integration_test.go b/hugolib/page_time_integration_test.go index 20844abac..3053bea20 100644 --- a/hugolib/page_time_integration_test.go +++ b/hugolib/page_time_integration_test.go @@ -9,15 +9,20 @@ import ( ) var PAGE_WITH_INVALID_DATE = `--- -date: 2010-05-02 15:29:31+08:00 +date: 2010-05-02_15:29:31+08:00 --- -Page With Invalid Date (missing the T for RFC 3339)` +Page With Invalid Date (replace T with _ for RFC 3339)` var PAGE_WITH_DATE_RFC3339 = `--- date: 2010-05-02T15:29:31+08:00 --- Page With Date RFC3339` +var PAGE_WITH_DATE_RFC3339_NO_T = `--- +date: 2010-05-02 15:29:31+08:00 +--- +Page With Date RFC3339_NO_T` + var PAGE_WITH_DATE_RFC1123 = `--- date: Sun, 02 May 2010 15:29:31 PST --- @@ -53,6 +58,21 @@ date: Sun May 02 15:29:31 +0800 2010 --- Page With Date RubyDate` +var PAGE_WITH_DATE_HugoYearNumeric = `--- +date: 2010-05-02 +--- +Page With Date HugoYearNumeric` + +var PAGE_WITH_DATE_HugoYear = `--- +date: 02 May 2010 +--- +Page With Date HugoYear` + +var PAGE_WITH_DATE_HugoLong = `--- +date: 02 May 2010 15:29 PST +--- +Page With Date HugoLong` + func TestDegenerateDateFrontMatter(t *testing.T) { p, _ := ReadFrom(strings.NewReader(PAGE_WITH_INVALID_DATE), "page/with/invalid/date") if p.Date != time.Unix(0, 0) { @@ -66,10 +86,13 @@ func TestParsingDateInFrontMatter(t *testing.T) { dt string }{ {PAGE_WITH_DATE_RFC3339, "2010-05-02T15:29:31+08:00"}, + {PAGE_WITH_DATE_RFC3339_NO_T, "2010-05-02T15:29:31+08:00"}, {PAGE_WITH_DATE_RFC1123Z, "2010-05-02T15:29:31+08:00"}, {PAGE_WITH_DATE_RFC822Z, "2010-05-02T15:29:00+08:00"}, {PAGE_WITH_DATE_ANSIC, "2010-05-02T15:29:31Z"}, {PAGE_WITH_DATE_RubyDate, "2010-05-02T15:29:31+08:00"}, + {PAGE_WITH_DATE_HugoYearNumeric, "2010-05-02T00:00:00Z"}, + {PAGE_WITH_DATE_HugoYear, "2010-05-02T00:00:00Z"}, } tzShortCodeTests := []struct { @@ -77,8 +100,9 @@ func TestParsingDateInFrontMatter(t *testing.T) { dt string }{ {PAGE_WITH_DATE_RFC1123, "2010-05-02T15:29:31-08:00"}, - {PAGE_WITH_DATE_RFC822, "2010-05-02T15:29:00-08:00"}, + {PAGE_WITH_DATE_RFC822, "2010-05-02T15:29:00-08:00Z"}, {PAGE_WITH_DATE_UnixDate, "2010-05-02T15:29:31-08:00"}, + {PAGE_WITH_DATE_HugoLong, "2010-05-02T15:21:00+08:00"}, } if _, err := time.LoadLocation("PST"); err == nil {