Prechádzať zdrojové kódy

feat(config): add configurable timestamp format with time_format field (#181)

ayntgl 3 rokov pred
rodič
commit
46aa968f7f
2 zmenil súbory, kde vykonal 4 pridanie a 1 odobranie
  1. 3 0
      config/config.go
  2. 1 1
      ui/builder.go

+ 3 - 0
config/config.go

@@ -5,6 +5,7 @@ import (
 	"os"
 	"path/filepath"
 	"runtime"
+	"time"
 
 	"github.com/BurntSushi/toml"
 )
@@ -41,6 +42,7 @@ type Config struct {
 	Timestamps             bool           `toml:"timestamps"`
 	MessagesLimit          uint           `toml:"messages_limit"`
 	Timezone               string         `toml:"timezone"`
+	TimeFormat             string         `toml:"time_format"`
 	AttachmentDownloadsDir string         `toml:"attachment_downloads_dir"`
 	Identify               IdentifyConfig `toml:"identify"`
 	Theme                  ThemeConfig    `toml:"theme"`
@@ -53,6 +55,7 @@ func New() *Config {
 		Timestamps:             false,
 		MessagesLimit:          50,
 		Timezone:               "Local",
+		TimeFormat:             time.Stamp,
 		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",

+ 1 - 1
ui/builder.go

@@ -29,7 +29,7 @@ func buildMessage(app *App, m discord.Message) []byte {
 			}
 
 			b.WriteString("[::d]")
-			b.WriteString(m.Timestamp.Time().In(loc).Format(time.Stamp))
+			b.WriteString(m.Timestamp.Time().In(loc).Format(app.Config.TimeFormat))
 			b.WriteString("[::-]")
 			b.WriteByte(' ')
 		}