toLocal template function

Hi. This adds a template function to convert a time to the local time zone. And modifies
the default quoted_reply template to use it and show the time zone when formatting the
timestamp of the quoted message.

Previously, the quoted message timestamp was UTC and it would format it without the time
zone. And I thought it might be a little confusing or weird to some normal people when I
email them and I don't want normal people to be confused or think that I'm weird.
This commit is contained in:
sqwishy 2020-02-24 15:38:20 -08:00 committed by Drew DeVault
parent 5dd0f454c1
commit 2fcd77f101
2 changed files with 6 additions and 1 deletions

View File

@ -156,11 +156,16 @@ func cmd(cmd, text string) string {
return out.String() return out.String()
} }
func toLocal(t time.Time) time.Time {
return time.Time.In(t, time.Local)
}
var templateFuncs = template.FuncMap{ var templateFuncs = template.FuncMap{
"quote": quote, "quote": quote,
"wrapText": wrapText, "wrapText": wrapText,
"wrap": wrap, "wrap": wrap,
"dateFormat": time.Time.Format, "dateFormat": time.Time.Format,
"toLocal": toLocal,
"exec": cmd, "exec": cmd,
} }

View File

@ -1,2 +1,2 @@
On {{dateFormat .OriginalDate "Mon Jan 2, 2006 at 3:04 PM"}}, {{(index .OriginalFrom 0).Name}} wrote: On {{dateFormat (.OriginalDate | toLocal) "Mon Jan 2, 2006 at 3:04 PM PST"}}, {{(index .OriginalFrom 0).Name}} wrote:
{{wrapText .OriginalText 72 | quote }} {{wrapText .OriginalText 72 | quote }}