From ec480412c4b4460625a7dc304ec0a63d0619913a Mon Sep 17 00:00:00 2001 From: delthas Date: Mon, 17 Oct 2022 14:17:05 +0200 Subject: Fix requesting CHATHISTORY TARGETS with invalid timestamps Previously, we sent the CHATHISTORY TARGETS start time with an incorrect offset equal to the system time offset. This means that we only reopened private buffers from the last app close + N hours on a system with a N-hour time offset. This fixes the issue by saving the stamp as UTC, and also making sure to format any time offset correctly. --- cmd/senpai/main.go | 7 ++++--- irc/session.go | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cmd/senpai/main.go b/cmd/senpai/main.go index 241c4c3..6434182 100644 --- a/cmd/senpai/main.go +++ b/cmd/senpai/main.go @@ -89,7 +89,7 @@ func getLastBuffer() (netID, buffer string) { return "", "" } - fields := strings.SplitN(string(buf), " ", 2) + fields := strings.SplitN(strings.TrimSpace(string(buf)), " ", 2) if len(fields) < 2 { return "", "" } @@ -116,7 +116,8 @@ func getLastStamp() time.Time { return time.Time{} } - t, err := time.Parse(time.RFC3339Nano, string(buf)) + stamp := strings.TrimSpace(string(buf)) + t, err := time.Parse(time.RFC3339Nano, stamp) if err != nil { return time.Time{} } @@ -129,7 +130,7 @@ func writeLastStamp(app *senpai.App) { if last.IsZero() { return } - err := os.WriteFile(lastStampPath, []byte(last.Format(time.RFC3339Nano)), 0666) + err := os.WriteFile(lastStampPath, []byte(last.UTC().Format(time.RFC3339Nano)), 0666) if err != nil { fmt.Fprintf(os.Stderr, "failed to write last stamp at %q: %s\n", lastStampPath, err) } diff --git a/irc/session.go b/irc/session.go index 63de30f..f4b3dfd 100644 --- a/irc/session.go +++ b/irc/session.go @@ -514,6 +514,7 @@ type HistoryRequest struct { } func formatTimestamp(t time.Time) string { + t = t.UTC() return fmt.Sprintf("timestamp=%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), t.Nanosecond()/1e6) } -- cgit v1.2.3