HELP !! Why isdoesn't it run on my machine ???

Mathias Koerber koerberm at nixsin.UUCP
Fri Sep 8 16:37:34 AEST 1989


Subject: HELP !  Why doesn't it run on my machine ?
Newsgroups: nix.general,comp.unix.wizards
Keywords: Dateconversion

I recently posted a request for date conversion routine, and one answer I got
was from Paul Regent (paulr at sequent), who sent me his routine. It loked good 
to me, so i tried it. But, I didn't run. So i checked it out and sent it back
to Paul with a lot of output and debug-information. He answered, that on his
machine it runs, and sent me some of his runs. I still can't figure out, what
is different on our machines. I include the code here, so maybe someone can
point out the mistake to me.

BTW: Paul has some BSD system, while I have tried it out on two systems.
One is a Nixdorf Targon/31 M30 running SysV (TOS 3.2.50);
The other is a Targon/35 running SysV AND UCB:
			TOS32DN nixsin TOS 3.2-06 0511m TARGON/35

ANSWERS: PLEASE USE THE ADDRESSES IN MY SIGNATURE, AS MY MAILER INCLUDES SOME
INFORMATION WHICH IS NOT KNOWN TO THE OUTSIDE WORLD.

Thx,
Mathias

And here the code:
---- cut here ----

#define Seconds_per_minute 60
#define Seconds_per_hour   60*Seconds_per_minute
#define Seconds_per_day    24*Seconds_per_hour
#define Seconds_per_month  30*Seconds_per_day
#define Seconds_per_year   365*Seconds_per_day

#include <sys/types.h>
#include <sys/time.h>

time_t
tm_to_time_t(t)
struct tm t;
{
    time_t high_guess = 0,low_guess = 0,middle;
    struct tm *temp;
    int score_high,score_low,nyears,low = 0,high = 0;
    static int fudges[12] = { 0*Seconds_per_day, /* Jan. */
				    1*Seconds_per_day, /* Feb. */
				   -1*Seconds_per_day, /* Mar. */
				    0*Seconds_per_day, /* Apr. */
				    0*Seconds_per_day, /* May  */
				    1*Seconds_per_day, /* Jun. */
				    1*Seconds_per_day, /* Jul. */
				    2*Seconds_per_day, /* Aug. */
				    3*Seconds_per_day, /* Sep. */
				    3*Seconds_per_day, /* Oct. */
				    4*Seconds_per_day, /* Nov. */
				    4*Seconds_per_day  /* Dec. */    };

    nyears = t.tm_year - 70;
    low_guess = Seconds_per_year*nyears +
             (double) ((nyears-1)*Seconds_per_day) * 0.24 +  /* add in leap days... */
	     Seconds_per_month*t.tm_mon +
	     fudges[t.tm_mon] +                         /* Add in approximate days for 'non-30' day months. */
	    Seconds_per_day*(t.tm_mday - 1) + Seconds_per_hour*t.tm_hour + Seconds_per_minute*t.tm_min + t.tm_sec;
    high_guess = low_guess + 2*Seconds_per_day;

    while (abs((high_guess - low_guess)) > 1) {
	middle = (high_guess + low_guess) / 2;
	temp = localtime(&middle);

	score_high = ((temp->tm_year > t.tm_year) << 5) + ((temp->tm_mon > t.tm_mon) << 4) + ((temp->tm_mday > t.tm_mday) << 3) +
		((temp->tm_hour > t.tm_hour) << 2) + ((temp->tm_min > t.tm_min) << 1) + (temp->tm_sec > t.tm_sec);
	score_low = ((temp->tm_year < t.tm_year) << 5) + ((temp->tm_mon < t.tm_mon) << 4) + ((temp->tm_mday < t.tm_mday) << 3) +
		((temp->tm_hour < t.tm_hour) << 2) + ((temp->tm_min < t.tm_min) << 1) + (temp->tm_sec < t.tm_sec);

	if (score_high > score_low)
		high_guess = middle,high++;
	else
		low_guess = middle,low++;
    }

    return middle;
}

main(argc,argv)
    int argc;
    char *argv[];
{
    struct tm z;
    time_t    t;

    z.tm_hour = atoi(argv[1]);
    z.tm_min  = atoi(argv[2]);
    z.tm_sec  = atoi(argv[3]);
    z.tm_mday = atoi(argv[4]);
    z.tm_mon  = atoi(argv[5]);
    z.tm_year = atoi(argv[6]);

    t = tm_to_time_t(z);
    printf("%d is the time representation for: %s",t,ctime(&t));
}
---- cut here ----

And here some results (from my side):
---- cut here ----
time2 0 0 0 1 0 70
-20734 is the time representation for: Thu Jan  1 02:14:26 1970
# Here the hours are somewhat wrong 

time2 0 0 0 8 8 89
621187200 is the time representation for: Fri Sep  8 00:00:00 1989
# OK !

time2 0 0 0 2 2 71
36720001 is the time representation for: Tue Mar  2 08:00:01 1971
# again, WRONG !

time2 0 0 0 6 2 93
731347201 is the time representation for: Sat Mar  6 00:00:01 1993
# OK !

time2 0 0 0 9 9 99
939403008 is the time representation for: Sat Oct  9 01:16:48 1999
# WRONG !!

time2 0 0 0 1 0 87
536443776 is the time representation for: Thu Jan  1 04:09:36 1987
# WRONG

-- 
-Mathias Koerber           |Tel:   +65 / 7473828 ext 322 |Fax: +65 / 7474331
-Nixdorf Computer Singapore|EUnet: koerber.sin at nixpbe    |nerv:  koerber.sin
-2 Kallang Sector          |uunet: uunet!linus!nixbur!koerber.sin
-Singapore 1334            |[Standard-disclaimer:All views personal...     ]



More information about the Comp.unix.wizards mailing list