Matrix-Zeitzone konfigurierbar machen (Default Europe/Berlin)

This commit is contained in:
Kai
2026-02-17 16:45:29 +01:00
parent 0185414e40
commit 5c8e985851
4 changed files with 19 additions and 1 deletions

View File

@@ -21,6 +21,7 @@ type MatrixClient struct {
AccessToken string
RoomID string
Limit int
TimeLocation *time.Location
httpClient *http.Client
crypto *cryptohelper.CryptoHelper
}
@@ -50,6 +51,12 @@ func newMatrixClientFromEnv() *MatrixClient {
Timeout: 8 * time.Second,
},
}
locName := strings.TrimSpace(readEnv("MATRIX_TIMEZONE", "Europe/Berlin"))
if loc, err := time.LoadLocation(locName); err == nil {
m.TimeLocation = loc
} else {
m.TimeLocation = time.Local
}
if readEnv("MATRIX_ENABLE_CRYPTO", "1") != "0" {
m.crypto = initMatrixCrypto(hs, token)
@@ -128,7 +135,7 @@ func (m *MatrixClient) FetchRecentMessages(ctx context.Context) ([]MatrixMessage
}
func (m *MatrixClient) mapEventToMessage(ctx context.Context, ev *event.Event) (MatrixMessage, bool) {
ts := time.UnixMilli(ev.Timestamp).Local().Format("02.01.2006 15:04")
ts := m.formatTimestamp(ev.Timestamp)
sender := shortMatrixSender(string(ev.Sender))
switch ev.Type {
@@ -152,6 +159,14 @@ func (m *MatrixClient) mapEventToMessage(ctx context.Context, ev *event.Event) (
}
}
func (m *MatrixClient) formatTimestamp(tsMillis int64) string {
loc := m.TimeLocation
if loc == nil {
loc = time.Local
}
return time.UnixMilli(tsMillis).In(loc).Format("02.01.2006 15:04")
}
func extractBody(ev *event.Event) (string, bool) {
if ev == nil {
return "", false