summaryrefslogtreecommitdiff
path: root/internal/util/time.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2025-04-06 14:55:35 +0200
committerLibravatar GitHub <noreply@github.com>2025-04-06 14:55:35 +0200
commite263d236223defbbdf9762cca57720da1d77c3ca (patch)
tree5c7f890c9c7aef2addd8270d3b255c3fe6075cbf /internal/util/time.go
parent[chore] Migrate accounts to new table, relax uniqueness constraint of actor `... (diff)
downloadgotosocial-e263d236223defbbdf9762cca57720da1d77c3ca.tar.xz
[bugfix] Change email `Date` header to use RFC2822 (#3972)
Diffstat (limited to 'internal/util/time.go')
-rw-r--r--internal/util/time.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/internal/util/time.go b/internal/util/time.go
index 0f874986a..9ea8d0c93 100644
--- a/internal/util/time.go
+++ b/internal/util/time.go
@@ -19,9 +19,11 @@ package util
import "time"
-// ISO8601 is a formatter for serializing times that forces ISO8601 behavior.
-const ISO8601 = "2006-01-02T15:04:05.000Z"
-const ISO8601Date = "2006-01-02"
+const (
+ ISO8601 = "2006-01-02T15:04:05.000Z"
+ ISO8601Date = "2006-01-02"
+ RFC2822 = "Mon, 02 Jan 2006 15:04:05 -0700"
+)
// FormatISO8601 converts the given time to UTC and then formats it
// using the ISO8601 const, which the Mastodon API is able to understand.
@@ -39,3 +41,11 @@ func FormatISO8601Date(t time.Time) string {
func ParseISO8601(in string) (time.Time, error) {
return time.Parse(ISO8601, in)
}
+
+// FormatRFC2822 converts the given time to local and then formats it using
+// the RFC2822 const, which conforms with email Date header requirements.
+//
+// See: https://www.rfc-editor.org/rfc/rfc2822#section-3.3
+func FormatRFC2822(t time.Time) string {
+ return t.Local().Format(RFC2822)
+}