apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: apr/time/unix time.c
Date Sun, 01 Jul 2001 21:47:54 GMT
brane       01/07/01 14:47:54

  Modified:    time/unix time.c
  Log:
  Adjust the calculated GMT offset on get_offset() for daylight savings time.
  This only affects platforms that do not have a tm_gmtoff field in struct tm
  (e.g., Solaris 2.6, HP-UX 10.20, ...).
  
  Revision  Changes    Path
  1.49      +12 -2     apr/time/unix/time.c
  
  Index: time.c
  ===================================================================
  RCS file: /home/cvs/apr/time/unix/time.c,v
  retrieving revision 1.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- time.c	2001/06/30 09:50:29	1.48
  +++ time.c	2001/07/01 21:47:53	1.49
  @@ -77,18 +77,28 @@
   #elif defined(HAVE___OFFSET)
       return tm->__tm_gmtoff;
   #else
  -    /* we don't have an offset field to use, so calculate it */
  +    /* We don't have an offset field to use, so calculate it.
  +       mktime() is the inverse of localtime(); so, presumably,
  +       passing in a struct tm made by gmtime() let's us calculate
  +       the true GMT offset. However, there's a catch: if daylight
  +       savings is in effect, gmtime()will set the tm_isdst field
  +       and confuse mktime() into returning a time that's offset
  +       by one hour. In that case, we must adjust the calculated GMT
  +       offset. */
       {
           time_t t1 = time(0), t2 = 0;
           struct tm t;
  +        int was_dst;
   
   #if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
           gmtime_r(&t1, &t);
   #else
           t = *gmtime(&t1);
   #endif
  +        was_dst = (t.tm_isdst > 0);
  +        t.tm_isdst = -1;
           t2 = mktime(&t);
  -        return (apr_int32_t) difftime(t1, t2);
  +        return (apr_int32_t) difftime(t1, t2) + (was_dst ? 3600 : 0);
       }
   #endif
   }
  
  
  

Mime
View raw message