mirror of
https://github.com/iyear/tdl
synced 2025-01-05 10:27:16 +08:00
fix(tplfunc): convert date arg to int64 with the best effort
This commit is contained in:
parent
c2b705efd8
commit
245b42a115
@ -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")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user