Commit 3ef02dc4 authored by Kim Vandry's avatar Kim Vandry

Interpret dates in search terms in the local timezone, including DST.

Previously, dates in search terms were interpreted in the local time
zone, but not taking into account that the current local DST offset
may not be the same as the DST offset on the specified date.

This can cause certain dates to be interpreted off-by-one at certain
times of the year in certain time zones. For example, where I am
right now, TZ=Europe/London, and at this time of year (summer),
dates in the winter are intrepreted incorrectly in this manner. This
breaks the test suite.

This patch does not completely fix date processing in mairix. There
are three salient timezones in mairix's operation:

1. The timezone specified in the messages (RFC 822 headers include it).
2. The timezone mairix was running in when it built the database.
3. The timezone that gets attached to dates in the search criteria.

This patch fixes (3). The design intent has never been made clear, but
I believe that midnight local time (for start dates) and 23:59:59
local time (for end dates) in the timezone in which mairix is running
is the most reasonable and unsurprising interpretation of those dates.

Now, (2) should have no bearing on anything at all, but it does,
because of the way times and timezones are ignored in rfc822.c. In other
words, (2) matters because (1) is done improperly. This should ideally
be fixed, but is more work, especially because doing it properly
requires the non-portable function timegm().

But at least with this patch the test suite now passes, in many
different timezones that I tried (partly thanks to the fact that in
the tests, mairix always builds the index in the same timezone as
the search happens in).

Fixes rc0/mairix#8
parent 96c4111b
......@@ -336,9 +336,11 @@ int scan_date_string(char *in, time_t *start, int *has_start, time_t *end, int *
start_tm.tm_hour = 0;
start_tm.tm_min = 0;
start_tm.tm_sec = 0;
start_tm.tm_isdst = -1;
end_tm.tm_hour = 23;
end_tm.tm_min = 59;
end_tm.tm_sec = 59;
end_tm.tm_isdst = -1;
hyphen = strchr(in, '-');
if (!hyphen) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment