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/win32 time.c
Date Sun, 09 Jun 2002 20:25:51 GMT
brane       2002/06/09 13:25:51

  Modified:    test     testtime.c
               time/win32 time.c
  Log:
  Fix calculation of tm_gmtoff on Windows, and add a test case.
  
  Revision  Changes    Path
  1.33      +47 -10    apr/test/testtime.c
  
  Index: testtime.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testtime.c,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- testtime.c	15 Apr 2002 00:01:09 -0000	1.32
  +++ testtime.c	9 Jun 2002 20:25:50 -0000	1.33
  @@ -62,6 +62,23 @@
   
   #define STR_SIZE 45
   
  +static const char* print_time (apr_pool_t *pool, const apr_time_exp_t *xt)
  +{
  +    return apr_psprintf (pool,
  +                         "%04d-%02d-%02d %02d:%02d:%02d.%06d %+05d [%d %s]%s",
  +                         xt->tm_year + 1900,
  +                         xt->tm_mon,
  +                         xt->tm_mday,
  +                         xt->tm_hour,
  +                         xt->tm_min,
  +                         xt->tm_sec,
  +                         xt->tm_usec,
  +                         xt->tm_gmtoff,
  +                         xt->tm_yday + 1,
  +                         apr_day_snames[xt->tm_wday],
  +                         (xt->tm_isdst ? " DST" : ""));
  +}
  +
   int main(void)
   {
       apr_time_t now;
  @@ -84,20 +101,39 @@
       printf("OK\n");
   
       STD_TEST_NEQ("    apr_time_exp_gmt", apr_time_exp_gmt(&xt, now))
  -    
  +    printf("        (%s)\n", print_time(p, &xt));
  +
       STD_TEST_NEQ("    apr_time_exp_lt", apr_time_exp_lt(&xt2, now))
  +    printf("        (%s)\n", print_time(p, &xt2));
   
       STD_TEST_NEQ("    apr_time_exp_get (GMT)", apr_time_exp_get(&imp, &xt))
   
       printf("%-60s", "    checking GMT explode == implode");
  -    if (imp != now) {
  -	printf("mismatch\n"
  +    hr_off_64 = (apr_int64_t) xt.tm_gmtoff * APR_USEC_PER_SEC;
  +    if (imp != now + hr_off_64) {
  +        printf("mismatch\n"
                   "\t\tapr_now()                %" APR_INT64_T_FMT "\n"
                   "\t\tapr_implode() returned   %" APR_INT64_T_FMT "\n"
                   "\t\terror delta was          %" APR_TIME_T_FMT "\n"
  -                "\t\tshould have been         0\n",
  -                now, imp, imp-now);
  -	exit(-1);
  +                "\t\tshould have been         %" APR_INT64_T_FMT "\n",
  +                now, imp, imp-now, hr_off_64);
  +       exit(-1);
  +    }
  +    printf("OK\n");
  +
  +    STD_TEST_NEQ("    apr_time_exp_get (localtime)",
  +                 apr_time_exp_get(&imp, &xt2))
  +
  +    printf("%-60s", "    checking localtime explode == implode");
  +    hr_off_64 = (apr_int64_t) xt2.tm_gmtoff * APR_USEC_PER_SEC;
  +    if (imp != now + hr_off_64) {
  +        printf("mismatch\n"
  +               "\t\tapr_now()                %" APR_INT64_T_FMT "\n"
  +               "\t\tapr_implode() returned   %" APR_INT64_T_FMT "\n"
  +               "\t\terror delta was          %" APR_TIME_T_FMT "\n"
  +               "\t\tshould have been         %" APR_INT64_T_FMT "\n",
  +               now, imp, imp-now, hr_off_64);
  +        exit(-1);
       }
       printf("OK\n");
   
  @@ -121,13 +157,13 @@
   
       printf("%-60s", "    checking localtime explode == GMT implode");
       if (imp != now) {
  -	printf("mismatch\n"
  +        printf("mismatch\n"
                   "\t\tapr_now()                %" APR_INT64_T_FMT "\n"
                   "\t\tapr_implode() returned   %" APR_INT64_T_FMT "\n"
                   "\t\terror delta was          %" APR_TIME_T_FMT "\n"
                   "\t\tshould have been         0\n",
                   now, imp, imp-now);
  -	exit(-1);
  +        exit(-1);
       }
       printf("OK\n");
   
  @@ -178,8 +214,9 @@
           exit(-1);
       }
       printf("OK\n");
  -    printf("        ( %lld - %lld = %lld )\n", imp, now, imp - now);
  - 
  +    printf("        ( %" APR_TIME_T_FMT " - %" APR_TIME_T_FMT
  +           " = %" APR_INT64_T_FMT " )\n", imp, now, imp - now);
  +
       printf("\nTest Complete.\n");
       return 0;
   }    
  
  
  
  1.35      +6 -4      apr/time/win32/time.c
  
  Index: time.c
  ===================================================================
  RCS file: /home/cvs/apr/time/win32/time.c,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- time.c	8 Jun 2002 20:04:26 -0000	1.34
  +++ time.c	9 Jun 2002 20:25:51 -0000	1.35
  @@ -105,16 +105,19 @@
       rc = GetTimeZoneInformation(&tz);
       switch (rc) {
       case TIME_ZONE_ID_UNKNOWN:
  -    case TIME_ZONE_ID_STANDARD:
           xt->tm_isdst = 0;
           /* Bias = UTC - local time in minutes 
            * tm_gmtoff is seconds east of UTC
            */
           xt->tm_gmtoff = tz.Bias * -60;
           break;
  +    case TIME_ZONE_ID_STANDARD:
  +        xt->tm_isdst = 0;
  +        xt->tm_gmtoff = (tz.Bias + tz.StandardBias) * -60;
  +        break;
       case TIME_ZONE_ID_DAYLIGHT:
           xt->tm_isdst = 1;
  -        xt->tm_gmtoff = tz.Bias * -60;
  +        xt->tm_gmtoff = (tz.Bias + tz.DaylightBias) * -60;
           break;
       default:
           xt->tm_isdst = 0;
  @@ -224,8 +227,7 @@
   {
       apr_status_t status = apr_time_exp_get(t, xt);
       if (status == APR_SUCCESS)
  -        *t -= (apr_time_t) (xt->tm_isdst * 3600 
  -                          + xt->tm_gmtoff) * APR_USEC_PER_SEC;
  +        *t -= (apr_time_t) xt->tm_gmtoff * APR_USEC_PER_SEC;
       return status;
   }
   
  
  
  

Mime
View raw message