commit ec48041
delthas
·
2022-10-17 12:17:05 +0000 UTC
parent 4ce085c
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.
2 files changed,
+5,
-3
+4,
-3
1@@ -89,7 +89,7 @@ func getLastBuffer() (netID, buffer string) {
2 return "", ""
3 }
4
5- fields := strings.SplitN(string(buf), " ", 2)
6+ fields := strings.SplitN(strings.TrimSpace(string(buf)), " ", 2)
7 if len(fields) < 2 {
8 return "", ""
9 }
10@@ -116,7 +116,8 @@ func getLastStamp() time.Time {
11 return time.Time{}
12 }
13
14- t, err := time.Parse(time.RFC3339Nano, string(buf))
15+ stamp := strings.TrimSpace(string(buf))
16+ t, err := time.Parse(time.RFC3339Nano, stamp)
17 if err != nil {
18 return time.Time{}
19 }
20@@ -129,7 +130,7 @@ func writeLastStamp(app *senpai.App) {
21 if last.IsZero() {
22 return
23 }
24- err := os.WriteFile(lastStampPath, []byte(last.Format(time.RFC3339Nano)), 0666)
25+ err := os.WriteFile(lastStampPath, []byte(last.UTC().Format(time.RFC3339Nano)), 0666)
26 if err != nil {
27 fmt.Fprintf(os.Stderr, "failed to write last stamp at %q: %s\n", lastStampPath, err)
28 }
+1,
-0
1@@ -514,6 +514,7 @@ type HistoryRequest struct {
2 }
3
4 func formatTimestamp(t time.Time) string {
5+ t = t.UTC()
6 return fmt.Sprintf("timestamp=%04d-%02d-%02dT%02d:%02d:%02d.%03dZ",
7 t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), t.Nanosecond()/1e6)
8 }