From d56ed15f8653582cc254d3bcc1e6d7346a5fd967 Mon Sep 17 00:00:00 2001 From: Lucille Tachet Date: Wed, 1 Aug 2018 11:05:11 +0200 Subject: [PATCH] datetime: use int64 instead of float64 --- template/helpers.go | 10 +++++----- template/helpers_test.go | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/template/helpers.go b/template/helpers.go index 2c810fb..87e86bd 100644 --- a/template/helpers.go +++ b/template/helpers.go @@ -46,22 +46,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 7dd4cd0..a9bf4e8 100644 --- a/template/helpers_test.go +++ b/template/helpers_test.go @@ -22,7 +22,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", @@ -33,8 +33,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) } } }