From 68d3baeac63a0793def69f0c3901ee24c14c7e2b Mon Sep 17 00:00:00 2001 From: Mike Pountney Date: Thu, 15 Oct 2015 12:43:03 +0100 Subject: [PATCH] Implement dateFormat template command Wrapper around time.Format, so that we can make concise lists without the whole JIRA ISO timestamp, eg: {{ dateFormat "2006-01-02T15:04" .fields.updated }} --- jira/cli/util.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/jira/cli/util.go b/jira/cli/util.go index d481496a..01d9c795 100644 --- a/jira/cli/util.go +++ b/jira/cli/util.go @@ -100,6 +100,14 @@ func fuzzyAge(start string) (string, error) { return "unknown", nil } +func dateFormat(format string, content string) (string, error) { + if t, err := time.Parse("2006-01-02T15:04:05.000-0700", content); err != nil { + return "", err + } else { + return t.Format(format), nil + } +} + func runTemplate(templateContent string, data interface{}, out io.Writer) error { if out == nil { @@ -171,6 +179,9 @@ func runTemplate(templateContent string, data interface{}, out io.Writer) error "age": func(content string) (string, error) { return fuzzyAge(content) }, + "dateFormat": func(format string, content string) (string, error) { + return dateFormat(format, content) + }, } if tmpl, err := template.New("template").Funcs(funcs).Parse(templateContent); err != nil { log.Error("Failed to parse template: %s", err)