summaryrefslogtreecommitdiffstats
path: root/tpl/time
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-03-17 22:03:27 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-03-17 22:03:27 +0100
commitb80853de90b10171155b8f3fde47d64ec7bfa0dd (patch)
tree435d3dbf7a495a0c6ce64c9769e037179aa0d27b /tpl/time
parent423594e03a906ef4150f433666ff588b022c3c92 (diff)
all: gofmt -w -r 'interface{} -> any' .
Updates #9687
Diffstat (limited to 'tpl/time')
-rw-r--r--tpl/time/init.go2
-rw-r--r--tpl/time/time.go8
-rw-r--r--tpl/time/time_test.go16
3 files changed, 13 insertions, 13 deletions
diff --git a/tpl/time/init.go b/tpl/time/init.go
index 0ef4fcdfd..a76348b7a 100644
--- a/tpl/time/init.go
+++ b/tpl/time/init.go
@@ -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
diff --git a/tpl/time/time.go b/tpl/time/time.go
index 21ebae4f8..66ea721fa 100644
--- a/tpl/time/time.go
+++ b/tpl/time/time.go
@@ -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
diff --git a/tpl/time/time_test.go b/tpl/time/time_test.go
index 0aeaed579..f368ea43f 100644
--- a/tpl/time/time_test.go
+++ b/tpl/time/time_test.go
@@ -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},