chathistory: Fix truncated backlog due to timezones v1 SUPERSEDED

Alex Karle: 1
 chathistory: Fix truncated backlog due to timezones

 1 files changed, 1 insertions(+), 1 deletions(-)
Thanks for the quick response and extra context!
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/soju-dev/patches/25561/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] chathistory: Fix truncated backlog due to timezones Export this patch

Because msgstore_fs writes logs in localetime, the CHATHISTORY
timestamps must be parsed as localtime too to ensure the right range is
sent back to the client.

Prior to this patch, the iteration back from the BEFORE time failed to
load the hours between midnight UTC and midnight localtime in each days
logged messages. This is because the final time to be considered in a
days log file (the "start" time) reuses the previous start time's

    start = time.Date(year, month, day, 0, 0, 0, 0, start.Location()).Add(-1)

By setting the original start (from the BEFORE timestamp) to localtime,
we ensure we read through midnight each day.


First off, thanks for soju! I've been using it since mid-summer and it's
been really solid and greatly improved my IRC experience.

Anthony (CC'd) and I hit this while testing out gamja + soju and this
patch fixed the issue for us!

As a practical example, here's the behavior on my EDT server
for message retrieval at 2021-10-06T01:00:00.000Z (9pm my time):

    -> start = 2021-10-06T01:00:00.000Z
    -> Try to read 2021-10-06.log (doesn't exist, still 9pm)
    -> Set start = 2021-10-06T00:00:00.000Z
    -> Read 2021-10-05.log up until 20:00:00, exit

Messages sent between 10pm and midnight were not sent back.

 irc.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/irc.go b/irc.go
index e78d48f..d71523e 100644
--- a/irc.go
+++ b/irc.go
@@ -652,7 +652,7 @@ func parseChatHistoryBound(param string) time.Time {
		if err != nil {
			return time.Time{}
		return timestamp
		return timestamp.In(time.Local)
		return time.Time{}
Thanks for sending a patch! I didn't notice the issue because my server's clock
is using UTC.

We inherit the timezone from the ZNC log format. There is a TODO item to make
that configurable [1].

If possible, I'd prefer to keep this fix local to msgstore_fs.go -- other
message stores may not have this limitation (e.g. the in-memory store doesn't,
and a DB-based store wouldn't either). Maybe we can just convert time values to
the local timezone at the start of each fsMessageStore.LoadXXX functions?

[1]: https://todo.sr.ht/~emersion/soju/53