apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dr...@apache.org
Subject cvs commit: apr/time/unix time.c timestr.c
Date Thu, 12 Apr 2001 16:50:51 GMT
dreid       01/04/12 09:50:51

  Modified:    include  apr_time.h
               time/unix time.c timestr.c
  Log:
  Some adjustments to the time code that gets us working better with timezones.
  Also change the beos sleep to use snooze instead of select.
  
  Revision  Changes    Path
  1.36      +13 -0     apr/include/apr_time.h
  
  Index: apr_time.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_time.h,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- apr_time.h	2001/04/12 07:05:49	1.35
  +++ apr_time.h	2001/04/12 16:50:49	1.36
  @@ -135,6 +135,19 @@
                                                       time_t input);
   
   /**
  + * convert a time to its human readable components using an offset
  + * from GMT
  + * @param result the exploded time
  + * @param input the time to explode
  + * @param offs the number of seconds offset to apply
  + * @param zone the zone description
  + * @deffunc apr_status_t apr_explode_time(apr_exploded_time_t *result, apr_time_t input,
apr_int32_t offs)
  + */
  +APR_DECLARE(apr_status_t) apr_explode_time(apr_exploded_time_t *result,
  +                                           apr_time_t input,
  +                                           apr_int32_t offs);
  +
  +/**
    * convert a time to its human readable components in GMT timezone
    * @param result the exploded time
    * @param input the time to explode
  
  
  
  1.38      +53 -68    apr/time/unix/time.c
  
  Index: time.c
  ===================================================================
  RCS file: /home/cvs/apr/time/unix/time.c,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- time.c	2001/02/25 20:39:40	1.37
  +++ time.c	2001/04/12 16:50:50	1.38
  @@ -56,6 +56,7 @@
   #include "apr_time.h"
   #include "apr_lib.h"
   #include "apr_private.h"
  +#include "apr_strings.h"
   /* System Headers required for time library */
   #if APR_HAVE_SYS_TIME_H
   #include <sys/time.h>
  @@ -66,9 +67,6 @@
   #ifdef HAVE_TIME_H
   #include <time.h>
   #endif
  -#ifdef BEOS
  -#include <sys/socket.h> /* for select */
  -#endif
   /* End System Headers */
   
   
  @@ -86,8 +84,28 @@
       return tv.tv_sec * APR_USEC_PER_SEC + tv.tv_usec;
   }
   
  +static void set_xt_gmtoff_from_tm(apr_exploded_time_t *xt, struct tm *tm,
  +                                  time_t *tt)
  +{
  +#ifdef HAVE_GMTOFF
  +    xt->tm_gmtoff = tm->tm_gmtoff;
  +#elif defined(HAVE___OFFSET)
  +    xt->tm_gmtoff = tm->__tm_gmtoff;
  +#else
  +    {
  +        struct tm t;
  +        int days = 0, hours = 0, minutes = 0;
  +        gmtime_r(tt, &t);
  +        days = xt->tm_yday - t.tm_yday;
  +        hours = ((days < -1 ? 24 : 1 < days ? -24 : days * 24) +
  +                 xt->tm_hour - t.tm_hour);
  +        minutes = hours * 60 + xt->tm_min - t.tm_min;
  +        xt->tm_gmtoff = minutes * 60;
  +    }
  +#endif
  +}
   
  -static void tm_to_exp(apr_exploded_time_t *xt, struct tm *tm)
  +static void tm_to_exp(apr_exploded_time_t *xt, struct tm *tm, time_t *tt)
   {
       xt->tm_sec  = tm->tm_sec;
       xt->tm_min  = tm->tm_min;
  @@ -98,82 +116,48 @@
       xt->tm_wday = tm->tm_wday;
       xt->tm_yday = tm->tm_yday;
       xt->tm_isdst = tm->tm_isdst;
  +    set_xt_gmtoff_from_tm(xt,tm,tt);
   }
  -
   
  -apr_status_t apr_explode_gmt(apr_exploded_time_t *result, apr_time_t input)
  +apr_status_t apr_explode_time(apr_exploded_time_t *result, apr_time_t input,
  +                              apr_int32_t offs)
   {
  -    time_t t = input / APR_USEC_PER_SEC;
  -#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
  -    struct tm banana;
  -#endif
  -
  +    time_t t = (input / APR_USEC_PER_SEC) + offs;
       result->tm_usec = input % APR_USEC_PER_SEC;
   
  -#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
  -    gmtime_r(&t, &banana);
  -    tm_to_exp(result, &banana);
  +#if APR_HAS_THREADS && defined (_POSIX_THREAD_SAFE_FUNCTIONS)
  +    {
  +        struct tm apple;
  +        gmtime_r(&t, &apple);
  +        tm_to_exp(result, &apple, &t);
  +    }
   #else
  -    tm_to_exp(result, gmtime(&t));
  +    tm_to_exp(result, gmtime(&t), &t);
   #endif
  -    result->tm_gmtoff = 0;
  +    result->tm_gmtoff = offs;
       return APR_SUCCESS;
   }
   
  -apr_status_t apr_explode_localtime(apr_exploded_time_t *result, apr_time_t input)
  +apr_status_t apr_explode_gmt(apr_exploded_time_t *result, apr_time_t input)
   {
  -#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
  -    time_t t = input / APR_USEC_PER_SEC;
  -    struct tm apricot;
  -
  -    result->tm_usec = input % APR_USEC_PER_SEC;
  -
  -    localtime_r(&t, &apricot);
  -    tm_to_exp(result, &apricot);
  -#if defined(HAVE_GMTOFF)
  -    result->tm_gmtoff = apricot.tm_gmtoff;
  -#elif defined(HAVE___GMTOFF)
  -    result->tm_gmtoff = apricot.__tm_gmtoff;
  -#else
  -    /* solaris is backwards enough to have pthreads but no tm_gmtoff, feh */
  -    {
  -	int days, hours, minutes;
  -
  -	gmtime_r(&t, &apricot);
  -	days = result->tm_yday - apricot.tm_yday;
  -	hours = ((days < -1 ? 24 : 1 < days ? -24 : days * 24)
  -		+ result->tm_hour - apricot.tm_hour);
  -	minutes = hours * 60 + result->tm_min - apricot.tm_min;
  -	result->tm_gmtoff = minutes * 60;
  -    }
  -#endif
  -#else
  -    time_t t = input / APR_USEC_PER_SEC;
  -    struct tm *tmx;
  +    return apr_explode_time(result, input, 0);
  +}
   
  -    result->tm_usec = input % APR_USEC_PER_SEC;
  +apr_status_t apr_explode_localtime(apr_exploded_time_t *result, apr_time_t input)
  +{
  +    time_t mango = input / APR_USEC_PER_SEC;
  +    apr_int32_t offs;
   
  -    tmx = localtime(&t);
  -    tm_to_exp(result, tmx);
  -#if defined(HAVE_GMTOFF)
  -    result->tm_gmtoff = tmx->tm_gmtoff;
  -#elif defined(HAVE___GMTOFF)
  -    result->tm_gmtoff = tmx->__tm_gmtoff;
  +#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
  +    struct tm mangotm;
  +    localtime_r(&mangotm, &mango);
  +    offs = mangotm.tm_gmtoff;
   #else
  -    /* need to create tm_gmtoff... assume we are never more than 24 hours away */
  -    {
  -	int days, hours, minutes;
  -
  -	tmx = gmtime(&t);
  -	days = result->tm_yday - tmx->tm_yday;
  -	hours = ((days < -1 ? 24 : 1 < days ? -24 : days * 24)
  -		+ result->tm_hour - tmx->tm_hour);
  -	minutes = hours * 60 + result->tm_min - tmx->tm_min;
  -	result->tm_gmtoff = minutes * 60;
  -    }
  +    struct tm *mangotm;
  +    mangotm=localtime(&mango);
  +    offs = mangotm->tm_gmtoff;
   #endif
  -#endif
  -    return APR_SUCCESS;
  +    return apr_explode_time(result, input, offs);
   }
   
   
  @@ -185,7 +169,6 @@
       {306, 337, 0, 31, 61, 92, 122, 153, 184, 214, 245, 275};
   
       year = xt->tm_year;
  -
       if (year < 70 || ((sizeof(time_t) <= 4) && (year >= 138))) {
           return APR_EBADDATE;
       }
  @@ -200,13 +183,11 @@
       days = year * 365 + year / 4 - year / 100 + (year / 100 + 3) / 4;
       days += dayoffset[xt->tm_mon] + xt->tm_mday - 1;
       days -= 25508;              /* 1 jan 1970 is 25508 days since 1 mar 1900 */
  -
       days = ((days * 24 + xt->tm_hour) * 60 + xt->tm_min) * 60 + xt->tm_sec;
   
       if (days < 0) {
           return APR_EBADDATE;
       }
  -    days -= xt->tm_gmtoff;
       *t = days * APR_USEC_PER_SEC + xt->tm_usec;
       return APR_SUCCESS;
   }
  @@ -230,6 +211,7 @@
       (*ostime)->tm_wday = aprtime->tm_wday;
       (*ostime)->tm_yday = aprtime->tm_yday;
       (*ostime)->tm_isdst = aprtime->tm_isdst;
  +    /* XXX - Need to handle gmt_offset's here ! */ 
       return APR_SUCCESS;
   }
   
  @@ -252,6 +234,7 @@
       aprtime->tm_wday = (*ostime)->tm_wday;
       aprtime->tm_yday = (*ostime)->tm_yday;
       aprtime->tm_isdst = (*ostime)->tm_isdst;
  +    /* XXX - Need to handle gmt_offsets here */
       return APR_SUCCESS;
   }
   
  @@ -259,6 +242,8 @@
   {
   #ifdef OS2
       DosSleep(t/1000);
  +#elseif defined(BEOS)
  +    snooze(t);
   #else
       struct timeval tv;
       tv.tv_usec = t % APR_USEC_PER_SEC;
  
  
  
  1.22      +1 -1      apr/time/unix/timestr.c
  
  Index: timestr.c
  ===================================================================
  RCS file: /home/cvs/apr/time/unix/timestr.c,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- timestr.c	2001/02/25 20:39:41	1.21
  +++ timestr.c	2001/04/12 16:50:50	1.22
  @@ -171,7 +171,6 @@
                           const char *format, apr_exploded_time_t *xt)
   {
       struct tm tm;
  -
       memset(&tm, 0, sizeof tm);
       tm.tm_sec  = xt->tm_sec;
       tm.tm_min  = xt->tm_min;
  @@ -182,6 +181,7 @@
       tm.tm_wday = xt->tm_wday;
       tm.tm_yday = xt->tm_yday;
       tm.tm_isdst = xt->tm_isdst;
  +    tm.tm_gmtoff = xt->tm_gmtoff;
       (*retsize) = strftime(s, max, format, &tm);
       return APR_SUCCESS;
   }
  
  
  

Mime
View raw message