diff -r cf398230331a -r 54b6f2a4098b printer/templateprinter.go --- a/printer/templateprinter.go Thu May 11 18:05:06 2017 +0200 +++ b/printer/templateprinter.go Thu May 11 18:05:06 2017 +0200 @@ -15,6 +15,7 @@ "reflect" "strings" "text/template" + "time" "github.com/m0t0k1ch1/gomif" "github.com/mattn/go-isatty" @@ -43,7 +44,8 @@ } t, err := template.New("output").Funcs(template.FuncMap{ "fromhtml": html2string, - "fromunix": unix2string, + "fromunix": unix2time, + "tolocal": dateToLocal, "color": ansiColor, "trim": strings.TrimSpace, "wrap": wrap, @@ -169,3 +171,13 @@ doc.ToText(&buf, text, indent, indent+" ", width) return buf.String() } + +// Parse datetime string from RFC3339 (default format in templates because +// of implicit conversion to string) and return a local time. +func dateToLocal(s string) (time.Time, error) { + t, err := time.Parse(time.RFC3339, s) + if err != nil { + return t, err + } + return t.Local(), err +}