Skip to content

Commit

Permalink
Implement dateFormat template command
Browse files Browse the repository at this point in the history
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 }}
  • Loading branch information
Mike Pountney committed Oct 15, 2015
1 parent 91e2475 commit 68d3bae
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions jira/cli/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 68d3bae

Please sign in to comment.