bug-classpath
[Top][All Lists]
Advanced

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

[Bug awt/57007] New: difftime buf


From: ch.derenne at gmail dot com
Subject: [Bug awt/57007] New: difftime buf
Date: Fri, 19 Apr 2013 16:11:34 +0000


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57007



             Bug #: 57007

           Summary: difftime buf

    Classification: Unclassified

           Product: classpath

           Version: unspecified

            Status: UNCONFIRMED

          Severity: normal

          Priority: P3

         Component: awt

        AssignedTo: address@hidden

        ReportedBy: address@hidden





So, I was developping an udflib for firebird, using gcc compiler, using

difftime.

Then I saw a strange thing about difftime which is in time.h:

It seems that if i use localtime, december of 1907 has only 30 days.

And if I use gmtime, then this is july 1941 who has only 30 days.

But all december and july have 31 days !





Just try to calculate seconds between 01-12-1907 and 01-01-1908, using

localtime,

you will see about 30 days dans some hours.



Now try to display the first of january 1908 at 0:00:00.000 using tm structure,

localtime , oohhh we are not at 0:00:00.000, why ?

1st december of 1907 is not at the same hour than 1st january 1908 (and i'm

using tm_hour=0, tm_min=0, tm_sec=0.......), so, tese are less than 31 days

bewtween those two dates.



Just try this :

I was using FC18 + gcc 4.7.2 (64 bits)

compiling with :

gcc -Wall test.c -o test







#include <stdio.h>

#include <stdlib.h>

#if TIME_WITH_SYS_TIME

# include <sys/time.h>

# include <time.h>

#else

# if HAVE_SYS_TIME_H

#  include <sys/time.h>

# else

#  include <time.h>

# endif

#endif

#include <string.h>

#include <math.h>

int main()

{

      time_t t1,t2 ;

      int d;

      double seconds;

      typedef struct tm tm;

      struct tm{

                   int tm_sec;int tm_min;int tm_hour;

                   int tm_mday;int tm_mon;int tm_year;

                   int tm_wday;int tm_yday;int tm_isdst;

               };

       tm *currtime = (tm*)malloc(sizeof( tm)); 

       t1 = time(NULL);

       currtime = localtime(&t1);

       currtime->tm_year = 8;

       currtime->tm_mon = 1;

       currtime->tm_mday = 1;

       currtime->tm_sec = 0;

       currtime->tm_min = 0;

       currtime->tm_hour = 0;

       t1=mktime(currtime);



       tm *depart = (tm*)malloc(sizeof( tm)); 

       t2 = time(NULL);

       depart = localtime(&t2);

       depart->tm_year = 7;

       depart->tm_mon = 12;

       depart->tm_mday = 1;

       depart->tm_sec = 0;

       depart->tm_min = 0;

       depart->tm_hour = 0;

       t2=mktime(depart);



    printf("start %s\n",ctime(&t2 ));

    printf("end %s\n",ctime(&t1 ));

       seconds = difftime(t1,t2);       

       d = ( seconds / 86400 );

       seconds = ( seconds - ( d * 86400 ) ); 

    printf("number of days %d\n, sec %lf",d,seconds);

    return 0;

}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]