fix(tplfunc): convert date arg to int64 with the best effort

This commit is contained in:
iyear 2024-11-29 15:25:08 +08:00
parent c2b705efd8
commit 245b42a115

View File

@ -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")
}