From 78316dafcda46970343984d10c551e9b72929615 Mon Sep 17 00:00:00 2001 From: Yuri van Oers Date: Sat, 28 Dec 2019 21:08:16 +0100 Subject: [PATCH] Use time type instead of string in notification template --- dkron/notifier.go | 9 +++++---- dkron/notifier_test.go | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/dkron/notifier.go b/dkron/notifier.go index 03396e98a..4e62f72cc 100644 --- a/dkron/notifier.go +++ b/dkron/notifier.go @@ -9,6 +9,7 @@ import ( "net/textproto" "strings" "text/template" + "time" "github.com/jordan-wright/email" "github.com/sirupsen/logrus" @@ -74,8 +75,8 @@ func (n *Notifier) buildTemplate(templ string) *bytes.Buffer { Report string JobName string ReportingNode string - StartTime string - FinishedAt string + StartTime time.Time + FinishedAt time.Time Success string NodeName string Output string @@ -83,8 +84,8 @@ func (n *Notifier) buildTemplate(templ string) *bytes.Buffer { n.report(), n.Execution.JobName, n.Config.NodeName, - fmt.Sprintf("%s", n.Execution.StartedAt), - fmt.Sprintf("%s", n.Execution.FinishedAt), + n.Execution.StartedAt, + n.Execution.FinishedAt, fmt.Sprintf("%t", n.Execution.Success), n.Execution.NodeName, fmt.Sprintf("%s", n.Execution.Output), diff --git a/dkron/notifier_test.go b/dkron/notifier_test.go index b767a18db..85ccd3acd 100644 --- a/dkron/notifier_test.go +++ b/dkron/notifier_test.go @@ -146,12 +146,12 @@ var templateTestCases = func(n *Notifier) []templateTestCase { }, { desc: "StartTime template variable", - exp: fmt.Sprintf("%s", n.Execution.StartedAt), + exp: n.Execution.StartedAt.String(), template: "{{.StartTime}}", }, { desc: "FinishedAt template variable", - exp: fmt.Sprintf("%s", n.Execution.FinishedAt), + exp: n.Execution.FinishedAt.String(), template: "{{.FinishedAt}}", }, {