Skip to content

Commit

Permalink
fix(tplfunc): convert date arg to int64 with the best effort
Browse files Browse the repository at this point in the history
  • Loading branch information
iyear committed Nov 29, 2024
1 parent c2b705e commit 245b42a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/tplfunc/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package tplfunc
import (
"text/template"
"time"

"github.com/spf13/cast"
)

var Date = []Func{Now(), FormatDate()}
Expand All @@ -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")
}
Expand Down

0 comments on commit 245b42a

Please sign in to comment.