• Kim Vandry's avatar
    Interpret dates in search terms in the local timezone, including DST. · 3ef02dc4
    Kim Vandry authored
    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
    3ef02dc4