diff --git a/template/helpers.go b/template/helpers.go index 134c28a..3c7a371 100644 --- a/template/helpers.go +++ b/template/helpers.go @@ -55,22 +55,22 @@ func init() { raymond.RegisterHelpers(funcs) } -func toDuration(started, finished float64) string { +func toDuration(started, finished int64) string { return fmt.Sprint(time.Duration(finished-started) * time.Second) } -func toDatetime(timestamp float64, layout, zone string) string { +func toDatetime(timestamp int64, layout, zone string) string { if len(zone) == 0 { - return time.Unix(int64(timestamp), 0).Format(layout) + return time.Unix(timestamp, 0).Format(layout) } loc, err := time.LoadLocation(zone) if err != nil { - return time.Unix(int64(timestamp), 0).Local().Format(layout) + return time.Unix(timestamp, 0).Local().Format(layout) } - return time.Unix(int64(timestamp), 0).In(loc).Format(layout) + return time.Unix(timestamp, 0).In(loc).Format(layout) } func isSuccess(conditional bool, options *raymond.Options) string { diff --git a/template/helpers_test.go b/template/helpers_test.go index 943399e..96d6e6e 100644 --- a/template/helpers_test.go +++ b/template/helpers_test.go @@ -20,7 +20,7 @@ import ( ) func TestToDuration(t *testing.T) { - from := float64(time.Date(2017, time.November, 15, 23, 0, 0, 0, time.UTC).Unix()) + from := time.Date(2017, time.November, 15, 23, 0, 0, 0, time.UTC).Unix() vals := map[int64]string{ time.Date(2018, time.November, 15, 23, 0, 0, 0, time.UTC).Unix(): "8760h0m0s", @@ -31,8 +31,8 @@ func TestToDuration(t *testing.T) { } for input, want := range vals { - if got := toDuration(from, float64(input)); got != want { - t.Errorf("Want transform %f-%f to %s, got %s", from, float64(input), want, got) + if got := toDuration(from, input); got != want { + t.Errorf("Want transform %d-%d to %s, got %s", from, input, want, got) } } }