Re: [gnome-db]Problems with a field date



On 22 May 2001 09:14:33 +0200, Vivien Malerba wrote:
> On Tue, May 22, 2001 at 01:04:31AM +0200, Rodrigo Moya wrote:
> > On 21 May 2001 11:51:34 -0500, Branly Abendano wrote:
> > > I think that I found the problem, someone know why is this in the code?.
> > > 
> > > In the gda-postgres-provider
> > > In the file:  gda-postgres-recordset.c
> > > 
> > > In the function:
> > > 
> > > static struct tm *
> > > str_to_tmstruct_date(gchar *date)
> > > {
> > >   int day, month, year;
> > >   char *ptr;
> > >   char mdate[11];
> > >   struct tm *stm;
> > > 
> > >   stm = (struct tm *) g_malloc(sizeof(struct tm));
> > >   if ((date==NULL) || (*date=='\0'))
> > >     {
> > >       g_free(stm);
> > >       return NULL;
> > >     }
> > > 
> > >   strncpy(mdate, date, 10);
> > >   mdate[10] = '\0';
> > >   ptr=(char *) strtok(mdate, "-/.");
> > >   month = atoi(ptr);
> > >  if (!(ptr=(char *) strtok(NULL, "-/.")))
> > >     {
> > >       g_free(stm);
> > >       return NULL; /* Error */
> > >     }
> > >   day=atoi(ptr);
> > >   if (!(ptr=(char *) strtok(NULL, "-/.")))
> > >     {
> > >       g_free(stm);
> > >       return NULL; /* Error */
> > >     }
> > >   year=atoi(ptr);
> > > 
> > >   stm->tm_mday = day;
> > >   stm->tm_mon = month -1;
> > >   stm->tm_year = year - 1900;
> > > 
> > >   return stm;
> > > }
> > > 
> > > In the last part the assigment is month-1 and year-1900. I don't know the
> > > reazon.
> > > 
> > > After this in the funcion
> > > 
> > > static void
> > > fill_field_values (Gda_ServerRecordset *recset, POSTGRES_Recordset *prc)
> > > 
> > > case GDA_TypeDbDate:
> > >               /* the date is DD-MM-YYYY, as set at connection opening */
> > >               stm = NULL;
> > >               if (native_value)
> > >                 {
> > >                   stm = str_to_tmstruct_date(native_value);
> > >                   if (stm)
> > >                     {
> > >                       GDate *date;
> > > 
> > >                       date = g_date_new_dmy(stm->tm_mday, stm->tm_mon,
> > the problem seen to be here with the month. The year is managed
> > correctly (-1900 before, +1900 now, but not the month, which should be,
> > I think, + 1. It's now changed on CVS, but try changing it in your local
> > copy, since right now CVS build is broken (sorry, my fault :-(
> > 
> 
> It has been done this way because the tm_mon field of struct tm is
> supposed to be from 0 to 11 (from the man pages) whereas AFAIK 
> we use 1 to 12 (or am I wrong?). It is the same thing for the year.
> 
yes, we use 1 to 12 (for glib's GDate functions), so was that the error?
(the +1)?

cheers
-- 
Rodrigo Moya <rodrigo gnome-db org> <rodrigo ximian com>
http://www.gnome-db.org/





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]