From 245b42a115e700bc8d6e8529a017b65fe5bc9e0b Mon Sep 17 00:00:00 2001 From: iyear Date: Fri, 29 Nov 2024 15:25:08 +0800 Subject: [PATCH] fix(tplfunc): convert date arg to int64 with the best effort --- pkg/tplfunc/date.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/tplfunc/date.go b/pkg/tplfunc/date.go index f65c025..e2f6e81 100644 --- a/pkg/tplfunc/date.go +++ b/pkg/tplfunc/date.go @@ -3,6 +3,8 @@ package tplfunc import ( "text/template" "time" + + "github.com/spf13/cast" ) var Date = []Func{Now(), FormatDate()} @@ -22,9 +24,9 @@ func FormatDate() Func { case 0: panic("formatDate() requires at least 1 argument") case 1: - return time.Unix(int64(args[0].(int)), 0).Format("20060102150405") + return time.Unix(cast.ToInt64(args[0]), 0).Format("20060102150405") case 2: - return time.Unix(int64(args[0].(int)), 0).Format(args[1].(string)) + return time.Unix(cast.ToInt64(args[0]), 0).Format(args[1].(string)) default: panic("formatDate() requires at most 2 arguments") }