A UNIX question
Piyush B. Sevalia
sevalia at eecs.umich.edu
Sat Apr 20 12:21:19 AEST 1991
Guys and Girls,
I have a small question which I hope you will be able to help me with.
I am using the following segment of code in my program. The problem
is explained after the code.
junk = (struct tm *)malloc(sizeof(struct tm));
junk->tm_sec = 0;
junk->tm_min = 0;
junk->tm_hour = 0;
junk->tm_mday = mday;
junk->tm_mon = mon - 1; /* 0-11 the range! */
junk->tm_year = year;
junk->tm_wday = 0;
junk->tm_yday = 0;
junk->tm_isdst = isdst;
*ptr = timegm(junk);
if (*ptr == -1)
{
printf("Error: Invalid date!\n");
exit(ERROR);
}
mday is the day of the month
mon is the month
year is the year
isdst is the daylight savings time flag.
The problem :
The code works fine if the daylight savings time is not in effect.
i.e. if the daylight savings time flag isdst is not 1.
However if it is one, timegm returns a -1, which is an error condition.
Note that ptr is of type int * .
Now could someone please tell me why this happens and
what should I do to rectify it ?
I have checked the SUN man pages (I work on the SUN Sparcstn 1+)
and I could not get much info there.
This is a slightly desperate situation and I have to
demo the program next week.
Please email me. I do not read this newsgroup, and it is the end of the
semester and I have a lot of projects due.
Thanks a lot,
Piyush Sevalia
Grad. Student
University of Michigan
Department of Electrical Engineering.
More information about the Comp.unix.questions
mailing list