diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2018-04-18 23:50:42 -0400 |
|---|---|---|
| committer | Dave Henderson <dhenderson@gmail.com> | 2018-04-18 23:50:42 -0400 |
| commit | e142ace1394fe56eec1cfdfb1c8a3db0efb6ff9f (patch) | |
| tree | 01498625109f9f92d82996864399ff1e3a5f088c /funcs/time.go | |
| parent | 3813bd30819c13047f385637d0f038dc84277633 (diff) | |
Relax inputs for many functions
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'funcs/time.go')
| -rw-r--r-- | funcs/time.go | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/funcs/time.go b/funcs/time.go index d3f55121..a1940584 100644 --- a/funcs/time.go +++ b/funcs/time.go @@ -7,6 +7,7 @@ import ( "sync" gotime "time" + "github.com/hairyhenderson/gomplate/conv" "github.com/hairyhenderson/gomplate/time" ) @@ -74,22 +75,22 @@ func (f *TimeFuncs) ZoneOffset() int { } // Parse - -func (f *TimeFuncs) Parse(layout, value string) (gotime.Time, error) { - return gotime.Parse(layout, value) +func (f *TimeFuncs) Parse(layout string, value interface{}) (gotime.Time, error) { + return gotime.Parse(layout, conv.ToString(value)) } // ParseLocal - -func (f *TimeFuncs) ParseLocal(layout, value string) (gotime.Time, error) { - return gotime.ParseInLocation(layout, value, gotime.Local) +func (f *TimeFuncs) ParseLocal(layout string, value interface{}) (gotime.Time, error) { + return gotime.ParseInLocation(layout, conv.ToString(value), gotime.Local) } // ParseInLocation - -func (f *TimeFuncs) ParseInLocation(layout, location, value string) (gotime.Time, error) { +func (f *TimeFuncs) ParseInLocation(layout, location string, value interface{}) (gotime.Time, error) { loc, err := gotime.LoadLocation(location) if err != nil { return gotime.Time{}, err } - return gotime.ParseInLocation(layout, value, loc) + return gotime.ParseInLocation(layout, conv.ToString(value), loc) } // Now - @@ -108,33 +109,33 @@ func (f *TimeFuncs) Unix(in interface{}) (gotime.Time, error) { } // Nanosecond - -func (f *TimeFuncs) Nanosecond(n int64) gotime.Duration { - return gotime.Nanosecond * gotime.Duration(n) +func (f *TimeFuncs) Nanosecond(n interface{}) gotime.Duration { + return gotime.Nanosecond * gotime.Duration(conv.ToInt64(n)) } // Microsecond - -func (f *TimeFuncs) Microsecond(n int64) gotime.Duration { - return gotime.Microsecond * gotime.Duration(n) +func (f *TimeFuncs) Microsecond(n interface{}) gotime.Duration { + return gotime.Microsecond * gotime.Duration(conv.ToInt64(n)) } // Millisecond - -func (f *TimeFuncs) Millisecond(n int64) gotime.Duration { - return gotime.Millisecond * gotime.Duration(n) +func (f *TimeFuncs) Millisecond(n interface{}) gotime.Duration { + return gotime.Millisecond * gotime.Duration(conv.ToInt64(n)) } // Second - -func (f *TimeFuncs) Second(n int64) gotime.Duration { - return gotime.Second * gotime.Duration(n) +func (f *TimeFuncs) Second(n interface{}) gotime.Duration { + return gotime.Second * gotime.Duration(conv.ToInt64(n)) } // Minute - -func (f *TimeFuncs) Minute(n int64) gotime.Duration { - return gotime.Minute * gotime.Duration(n) +func (f *TimeFuncs) Minute(n interface{}) gotime.Duration { + return gotime.Minute * gotime.Duration(conv.ToInt64(n)) } // Hour - -func (f *TimeFuncs) Hour(n int64) gotime.Duration { - return gotime.Hour * gotime.Duration(n) +func (f *TimeFuncs) Hour(n interface{}) gotime.Duration { + return gotime.Hour * gotime.Duration(conv.ToInt64(n)) } // convert a number input to a pair of int64s, representing the integer portion and the decimal remainder |
