This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

problem with getdate




As Hendrik reported, we seem to have a bug in getdate.  Calling
getdate twice gives different results for the value of tm_hour:

$ ./get_date_test_c   

DateString: 01-Aug-2000 05:06:07

1. conversion:
-------------------------------------------------------------
Data of struct tm: 
tm_sec   : 7
tm_min   : 6
tm_hour  : 6
tm_mday  : 1
tm_mon   : 7
tm_year  : 100
tm_wday  : 2
tm_yday  : 213
tm_isdst : 1
tm_gmtoff: 7200
tm_zone  : CEST
getdate: Tue Aug  1 06:06:07 2000

2. conversion:
-------------------------------------------------------------
Data of struct tm: 
tm_sec   : 7
tm_min   : 6
tm_hour  : 5
tm_mday  : 1
tm_mon   : 7
tm_year  : 100
tm_wday  : 2
tm_yday  : 213
tm_isdst : 1
tm_gmtoff: 7200
tm_zone  : CEST
getdate: Tue Aug  1 05:06:07 2000

The change from 5 to 6 in tm_hour occurs in the mktime call in getdate_r.

I'm appending the test files.  Has anybody an idea what's broken?

Andreas

/*
  compile cmd: gcc -Wall -D_GNU_SOURCE -o get_date_test_c get_date_c.c
  Don't forget to set your DATEMSK env var
*/

/*------------------ includes ----------------------------*/
#include <stdio.h>
#include <time.h>

/*------------------ externals ---------------------------*/

/*------------------ prototypes --------------------------*/
void
print(struct tm* tm);

/*------------------ main --------------------------------*/
int
main(int argc, char** argv)
{
  int i = 1;
  struct tm*  time_tm     = NULL;
  const char* aDateString = "01-Aug-2000 05:06:07";

  printf("\nDateString: %s\n\n", aDateString);

  for(;i < 3; i++)
  {
    printf("%d. conversion:\n", i);
    printf("-------------------------------------------------------------\n");
    time_tm = getdate(aDateString);
    if(getdate_err)
    {
      printf("Can't eval date string <%s>: %d\n", aDateString, getdate_err);
      getdate_err = 0;
    }
    else
    {
      print(time_tm);
      printf ("\ngetdate: %s\n", asctime(time_tm));
    }
  }

  return 0;
}

void
print(struct tm* tm)
{
  printf("Data of struct tm: \n"
         "tm_sec   : %d"
         "\ntm_min   : %d"
         "\ntm_hour  : %d"
         "\ntm_mday  : %d"
         "\ntm_mon   : %d"
         "\ntm_year  : %d"
         "\ntm_wday  : %d"
         "\ntm_yday  : %d"
         "\ntm_isdst : %d",
         tm->tm_sec, tm->tm_min, tm->tm_hour, tm->tm_mday, tm->tm_mon,
         tm->tm_year, tm->tm_wday, tm->tm_yday, tm->tm_isdst);
#ifdef	__USE_BSD
  printf("\ntm_gmtoff: %ld"
         "\ntm_zone  : %s",
         tm->tm_gmtoff, tm->tm_zone);
#endif
}
%d-%b-%Y %T
%d-%b-%y
%d-%b-%y %T
%d-%b-%y
%d.%m.%Y %T
%T
%d/%m/%y %T
%a %b %d %T %Y

-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.inka.de
    http://www.suse.de/~aj

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]