#3890: mutt_mktime is ambiguous near DST change
---------------------+----------------------
  Reporter:  vinc17  |      Owner:  mutt-dev
      Type:  defect  |     Status:  new
  Priority:  major   |  Milestone:
 Component:  mutt    |    Version:  1.7.1
Resolution:          |   Keywords:
---------------------+----------------------

Comment (by derekmartin):

 This seems to be the right idea.  But Mutt should not assume TZ is set:
 These days I think TZ is typically unset, and the system libraries rely on
 settings from /etc/localtime, at least on Linux.  So Mutt will probably
 need to do something like:

 {{{
     char *tz = getenv("TZ");
     setenv("TZ", "GMT", 1);
     /* do time conversion stuff */
     ...
     if (tz) setenv("TZ", tz, 1);
     else unsetenv("TZ");
     ...
 }}}

 There are places in Mutt where it needs to convert the sender's local
 time, but may not have enough information to accurately determine what the
 sender's DST context was for the date in question.  It does have the time
 offset, however, so it's probably sufficient to add the GMT offset to the
 struct tm before calling mktime on it.

 Note:  According to the man page, mktime() is supposed to "normalize" a
 struct tm that has fields with values that are out of the normal range for
 the field.  This program demonstrates that:

 {{{
 #include <time.h>
 #include <stdio.h>

 int main(int argc, char **argv)
 {
     struct tm now;
     struct tm later;
     struct tm *tmp;
     time_t start;

     start = time(NULL);
     tmp = gmtime(&start);
     now = *tmp;
     later = now;
     later.tm_sec += 3600;

     printf("Now = %ld\n", mktime(&now));
     printf("Later = %ld\n", mktime(&later));
     return 0;
 }

 $ gcc -o tm time.c
 $ ./tm
 Now = 1477436206
 Later = 1477439806

 }}}

 If this normalization is reliable on all platforms, it may be useful for
 part of what Mutt needs to do here.

--
Ticket URL: <https://dev.mutt.org/trac/ticket/3890#comment:2>
Mutt <http://www.mutt.org/>
The Mutt mail user agent

Reply via email to