Support for non-standard formats.

Forgot to include existing formats.  Integration tests include new
format.
This commit is contained in:
Noah Campbell 2013-08-12 14:13:31 -07:00
parent 0305c82513
commit 3fdcd0ba7c
2 changed files with 31 additions and 3 deletions

View file

@ -74,6 +74,10 @@ func interfaceToStringToDate(i interface{}) time.Time {
time.ANSIC, time.ANSIC,
time.UnixDate, time.UnixDate,
time.RubyDate, time.RubyDate,
"2006-01-02 15:04:05Z07:00",
"02 Jan 06 15:04 MST",
"2006-01-02",
"02 Jan 2006",
}); e == nil { }); e == nil {
return d return d
} }

View file

@ -9,15 +9,20 @@ import (
) )
var PAGE_WITH_INVALID_DATE = `--- 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 = `--- var PAGE_WITH_DATE_RFC3339 = `---
date: 2010-05-02T15:29:31+08:00 date: 2010-05-02T15:29:31+08:00
--- ---
Page With Date RFC3339` 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 = `--- var PAGE_WITH_DATE_RFC1123 = `---
date: Sun, 02 May 2010 15:29:31 PST 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` 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) { func TestDegenerateDateFrontMatter(t *testing.T) {
p, _ := ReadFrom(strings.NewReader(PAGE_WITH_INVALID_DATE), "page/with/invalid/date") p, _ := ReadFrom(strings.NewReader(PAGE_WITH_INVALID_DATE), "page/with/invalid/date")
if p.Date != time.Unix(0, 0) { if p.Date != time.Unix(0, 0) {
@ -66,10 +86,13 @@ func TestParsingDateInFrontMatter(t *testing.T) {
dt string dt string
}{ }{
{PAGE_WITH_DATE_RFC3339, "2010-05-02T15:29:31+08:00"}, {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_RFC1123Z, "2010-05-02T15:29:31+08:00"},
{PAGE_WITH_DATE_RFC822Z, "2010-05-02T15:29:00+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_ANSIC, "2010-05-02T15:29:31Z"},
{PAGE_WITH_DATE_RubyDate, "2010-05-02T15:29:31+08:00"}, {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 { tzShortCodeTests := []struct {
@ -77,8 +100,9 @@ func TestParsingDateInFrontMatter(t *testing.T) {
dt string dt string
}{ }{
{PAGE_WITH_DATE_RFC1123, "2010-05-02T15:29:31-08:00"}, {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_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 { if _, err := time.LoadLocation("PST"); err == nil {