This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


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

Date problem...


Hi,

I am having problems with dates. I am writing a program to create
importable files for a certain scheduler and for some reason some of the
events appear 1 hour earlier than when set. The following hex numbers are
in time_t format right from the datafile of the scheduler, they are to be
read in reverse (HOB, LOB order of things):

f0884334
70da4434
f02b4634
707d4734

They correspond to 8:00 AM entries for dates between october 14th - 17th
(it does the same thing during April 1-4). The following code takes these
hex numbers as command line input and outputs the date (took precaution to
invert it just in case I input HOB-LOB in the wrong order).

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


main(argc, argv)
char **argv;
int argc;
{
    time_t time_arg;
    char *strptr;
    char invert[BUFSIZ];
    int i,j=0,k;
    if ( argc < 2 ) exit(1);

    for ( k=1; k < argc ; k++ )
    {
        time_arg = (time_t) strtoul( argv[k], &strptr, 16 );
        printf("ctime %s %s\n",argv[k], ctime( &time_arg ));
        for ( i = strlen( argv[k] )-1 ; i >= 0 ; i-= 2 )
        {
            invert[j] = argv[k][i-1];
            invert[j+1] = argv[k][i];
            j+=2;
        }
        invert[j] = '\0';
        time_arg = (time_t) strtoul( invert, &strptr, 16 );

        printf("ctime %s %s\n", invert, ctime( &time_arg ));
        j=0;
    }
}

/*******************/
 From the above code I get all these events to be at 7:00 AM instead of
8:00 AM. 
Could someone tell me if I am doing something wrong or if I should blame
the scheduling software.

Here is the output, every second line is the correct date (due to HOB-LOB
invertion):

ctime f0884334 Wed Oct 11 03:10:44 1961

ctime 344388f0 Tue Oct 14 07:00:00 1997


ctime 70da4434 Sun Dec 30 11:15:00 2029

ctime 3444da70 Wed Oct 15 07:00:00 1997


ctime f02b4634 Tue Aug 01 15:22:44 1961

ctime 34462bf0 Thu Oct 16 07:00:00 1997


ctime 707d4734 Sat Oct 20 22:27:00 2029

ctime 34477d70 Fri Oct 17 07:00:00 1997


I am going nuts trying to figure this out. Any help greatly appreciated.

Narayan

| Narayan     _/~~~~ (253) 856-1564 ~~ venkman1@ix.netcom.com ~~~~~~~~~~~~/
|Natarajan  _/                                   .       .____ _       _/
|         _/ "I am not a vegetarian        *   .     x  -(____/ |  _  /
|       _/ because I love animals;              ________/____/  \ ( )-----
|     _/ I am a vegetarian because I          ,/                _ ( -------
|   _/  hate plants."                        <________\       //  (_)-----
| _/                                       --<==  *    |_____/  _
|/  http://www.netcom.com/~venkman1                   -(_____) (_)-----
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


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