URI: 
       Adding support for date field in front matter as date (as TOML provides) - hugo - [fork] hugo port for 9front
  HTML git clone git@git.drkhsh.at/hugo.git
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
   DIR README
   DIR LICENSE
       ---
   DIR commit 471fb1ff699473d7821812490b0ee472ecebb8b2
   DIR parent f3c816eabdaddc0939ddc70ac4e2aa3c16abcc11
  HTML Author: spf13 <steve.francia@gmail.com>
       Date:   Thu, 24 Oct 2013 15:18:57 -0700
       
       Adding support for date field in front matter as date (as TOML provides)
       
       Diffstat:
         M hugolib/metadata.go                 |      44 +++++++++++++++++++------------
         M hugolib/page.go                     |       4 ++--
         M hugolib/page_time_integration_test… |       4 ++--
       
       3 files changed, 31 insertions(+), 21 deletions(-)
       ---
   DIR diff --git a/hugolib/metadata.go b/hugolib/metadata.go
       @@ -8,10 +8,35 @@ import (
                "time"
        )
        
       +func interfaceToTime(i interface{}) time.Time {
       +        switch s := i.(type) {
       +        case time.Time:
       +                return s
       +        case string:
       +                d, e := stringToDate(s)
       +                if e == nil {
       +                        return d
       +                }
       +                errorf("Invalid Time/Date format")
       +        default:
       +                errorf("Only Time is supported for this key")
       +        }
       +
       +        return *new(time.Time)
       +}
       +
        func interfaceToStringToDate(i interface{}) time.Time {
                s := interfaceToString(i)
        
       -        if d, e := parseDateWith(s, []string{
       +        if d, e := stringToDate(s); e == nil {
       +                return d
       +        }
       +
       +        return time.Unix(0, 0)
       +}
       +
       +func stringToDate(s string) (time.Time, error) {
       +        return parseDateWith(s, []string{
                        time.RFC3339,
                        time.RFC1123Z,
                        time.RFC1123,
       @@ -24,11 +49,7 @@ func interfaceToStringToDate(i interface{}) time.Time {
                        "02 Jan 06 15:04 MST",
                        "2006-01-02",
                        "02 Jan 2006",
       -        }); e == nil {
       -                return d
       -        }
       -
       -        return time.Unix(0, 0)
       +        })
        }
        
        // TODO remove this and return a proper error.
       @@ -118,17 +139,6 @@ func interfaceToInt(i interface{}) int {
                return 0
        }
        
       -func interfaceToTime(i interface{}) time.Time {
       -        switch s := i.(type) {
       -        case time.Time:
       -                return s
       -        default:
       -                errorf("Only Time is supported for this key")
       -        }
       -
       -        return *new(time.Time)
       -}
       -
        func interfaceToString(i interface{}) string {
                switch s := i.(type) {
                case string:
   DIR diff --git a/hugolib/page.go b/hugolib/page.go
       @@ -348,7 +348,7 @@ func (page *Page) update(f interface{}) error {
                        case "keywords":
                                page.Keywords = interfaceArrayToStringArray(v)
                        case "date", "pubdate":
       -                        page.Date = interfaceToStringToDate(v)
       +                        page.Date = interfaceToTime(v)
                        case "draft":
                                page.Draft = interfaceToBool(v)
                        case "layout":
       @@ -384,7 +384,7 @@ func (page *Page) update(f interface{}) error {
                                                for i, u := range vvv {
                                                        a[i] = interfaceToString(u)
                                                }
       -                                        page.Params[strings.ToLower(k)] = a
       +                                        page.Params[loki] = a
                                        }
                                }
                        }
   DIR diff --git a/hugolib/page_time_integration_test.go b/hugolib/page_time_integration_test.go
       @@ -75,8 +75,8 @@ 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) {
       -                t.Fatalf("Date should be set to computer epoch.  Got: %s", p.Date)
       +        if p.Date != *new(time.Time) {
       +                t.Fatalf("Date should be set to time.Time zero value.  Got: %s", p.Date)
                }
        }