hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 35abd179e2e9d2dc25706e1922f4084bbad92533
parent 8d8fa7222f11f4003fa43c0914e9f66d276016a4
Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date:   Fri, 20 Nov 2015 11:53:25 +0100

Add time.Time support in ge, gt, le, lt

Fixes #1593

Diffstat:
Mtpl/template_funcs.go | 11++++++++++-
Mtpl/template_funcs_test.go | 4++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/tpl/template_funcs.go b/tpl/template_funcs.go
@@ -112,6 +112,11 @@ func compareGetFloat(a interface{}, b interface{}) (float64, float64) {
 			str := av.String()
 			leftStr = &str
 		}
+	case reflect.Struct:
+		switch av.Type() {
+		case timeType:
+			left = float64(timeUnix(av))
+		}
 	}
 
 	bv := reflect.ValueOf(b)
@@ -129,7 +134,11 @@ func compareGetFloat(a interface{}, b interface{}) (float64, float64) {
 			str := bv.String()
 			rightStr = &str
 		}
-
+	case reflect.Struct:
+		switch bv.Type() {
+		case timeType:
+			right = float64(timeUnix(bv))
+		}
 	}
 
 	switch {
diff --git a/tpl/template_funcs_test.go b/tpl/template_funcs_test.go
@@ -5,6 +5,7 @@ import (
 	"encoding/base64"
 	"errors"
 	"fmt"
+	"github.com/spf13/cast"
 	"html/template"
 	"path"
 	"reflect"
@@ -81,6 +82,9 @@ func doTestCompare(t *testing.T, tp tstCompareType, funcUnderTest func(a, b inte
 		{"8", "5", 1},
 		{"5", "0001", 1},
 		{[]int{100, 99}, []int{1, 2, 3, 4}, -1},
+		{cast.ToTime("2015-11-20"), cast.ToTime("2015-11-20"), 0},
+		{cast.ToTime("2015-11-19"), cast.ToTime("2015-11-20"), -1},
+		{cast.ToTime("2015-11-20"), cast.ToTime("2015-11-19"), 1},
 	} {
 		result := funcUnderTest(this.left, this.right)
 		success := false