mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-31 22:41:53 +02:00
@@ -32,7 +32,7 @@ func init() {
|
||||
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func(args ...interface{}) (interface{}, error) {
|
||||
Context: func(args ...any) (any, error) {
|
||||
// Handle overlapping "time" namespace and func.
|
||||
//
|
||||
// If no args are passed to `time`, assume namespace usage and
|
||||
|
@@ -42,7 +42,7 @@ type Namespace struct {
|
||||
|
||||
// AsTime converts the textual representation of the datetime string into
|
||||
// a time.Time interface.
|
||||
func (ns *Namespace) AsTime(v interface{}, args ...interface{}) (interface{}, error) {
|
||||
func (ns *Namespace) AsTime(v any, args ...any) (any, error) {
|
||||
loc := ns.location
|
||||
if len(args) > 0 {
|
||||
locStr, err := cast.ToStringE(args[0])
|
||||
@@ -62,7 +62,7 @@ func (ns *Namespace) AsTime(v interface{}, args ...interface{}) (interface{}, er
|
||||
// Format converts the textual representation of the datetime string into
|
||||
// the other form or returns it of the time.Time value. These are formatted
|
||||
// with the layout string
|
||||
func (ns *Namespace) Format(layout string, v interface{}) (string, error) {
|
||||
func (ns *Namespace) Format(layout string, v any) (string, error) {
|
||||
t, err := htime.ToTimeInDefaultLocationE(v, ns.location)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -82,7 +82,7 @@ func (ns *Namespace) Now() _time.Time {
|
||||
// such as "300ms", "-1.5h" or "2h45m".
|
||||
// Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
|
||||
// See https://golang.org/pkg/time/#ParseDuration
|
||||
func (ns *Namespace) ParseDuration(in interface{}) (_time.Duration, error) {
|
||||
func (ns *Namespace) ParseDuration(in any) (_time.Duration, error) {
|
||||
s, err := cast.ToStringE(in)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -109,7 +109,7 @@ var durationUnits = map[string]_time.Duration{
|
||||
|
||||
// Duration converts the given number to a time.Duration.
|
||||
// Unit is one of nanosecond/ns, microsecond/us/µs, millisecond/ms, second/s, minute/m or hour/h.
|
||||
func (ns *Namespace) Duration(unit interface{}, number interface{}) (_time.Duration, error) {
|
||||
func (ns *Namespace) Duration(unit any, number any) (_time.Duration, error) {
|
||||
unitStr, err := cast.ToStringE(unit)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
@@ -32,8 +32,8 @@ func TestTimeLocation(t *testing.T) {
|
||||
for i, test := range []struct {
|
||||
name string
|
||||
value string
|
||||
location interface{}
|
||||
expect interface{}
|
||||
location any
|
||||
expect any
|
||||
}{
|
||||
{"Empty location", "2020-10-20", "", "2020-10-20 00:00:00 +0000 UTC"},
|
||||
{"New location", "2020-10-20", nil, "2020-10-20 00:00:00 -0400 AST"},
|
||||
@@ -53,7 +53,7 @@ func TestTimeLocation(t *testing.T) {
|
||||
{"Invalid time value", "invalid-value", "", false},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
var args []interface{}
|
||||
var args []any
|
||||
if test.location != nil {
|
||||
args = append(args, test.location)
|
||||
}
|
||||
@@ -90,8 +90,8 @@ func TestFormat(t *testing.T) {
|
||||
|
||||
for i, test := range []struct {
|
||||
layout string
|
||||
value interface{}
|
||||
expect interface{}
|
||||
value any
|
||||
expect any
|
||||
}{
|
||||
{"Monday, Jan 2, 2006", "2015-01-21", "Wednesday, Jan 21, 2015"},
|
||||
{"Monday, Jan 2, 2006", time.Date(2015, time.January, 21, 0, 0, 0, 0, time.UTC), "Wednesday, Jan 21, 2015"},
|
||||
@@ -146,9 +146,9 @@ func TestDuration(t *testing.T) {
|
||||
ns := New(translators.GetTranslator("en"), time.UTC)
|
||||
|
||||
for i, test := range []struct {
|
||||
unit interface{}
|
||||
num interface{}
|
||||
expect interface{}
|
||||
unit any
|
||||
num any
|
||||
expect any
|
||||
}{
|
||||
{"nanosecond", 10, 10 * time.Nanosecond},
|
||||
{"ns", 10, 10 * time.Nanosecond},
|
||||
|
Reference in New Issue
Block a user