Explorar o código

feat: timestamps now respect local timezone by default (#177)

Closes #154
ayntgl %!s(int64=3) %!d(string=hai) anos
pai
achega
7813d7914d
Modificáronse 2 ficheiros con 8 adicións e 1 borrados
  1. 2 0
      config/config.go
  2. 6 1
      ui/builder.go

+ 2 - 0
config/config.go

@@ -40,6 +40,7 @@ type Config struct {
 	Mouse                  bool           `toml:"mouse"`
 	Timestamps             bool           `toml:"timestamps"`
 	MessagesLimit          int            `toml:"messages_limit"`
+	Timezone               string         `toml:"timezone"`
 	AttachmentDownloadsDir string         `toml:"attachment_downloads_dir"`
 	Identify               IdentifyConfig `toml:"identify"`
 	Theme                  ThemeConfig    `toml:"theme"`
@@ -51,6 +52,7 @@ func New() *Config {
 		Mouse:                  true,
 		Timestamps:             false,
 		MessagesLimit:          50,
+		Timezone:               "Local",
 		AttachmentDownloadsDir: UserDownloadsDir(),
 		Identify: IdentifyConfig{
 			UserAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36",

+ 6 - 1
ui/builder.go

@@ -24,8 +24,13 @@ func buildMessage(app *App, m *astatine.Message) []byte {
 		buildReferencedMessage(&b, m.ReferencedMessage, app.Session.State.User.ID)
 
 		if app.Config.Timestamps {
+			loc, err := time.LoadLocation(app.Config.Timezone)
+			if err != nil {
+				return nil
+			}
+
 			b.WriteString("[::d]")
-			b.WriteString(m.Timestamp.Format(time.Stamp))
+			b.WriteString(m.Timestamp.In(loc).Format(time.Stamp))
 			b.WriteString("[::-]")
 			b.WriteByte(' ')
 		}