PRB: mktime() Function Does Not Flag Invalid Dates Before 1970

ID Number: Q64436

6.00 6.00a 6.00ax | 6.00 6.00a

MS-DOS | OS/2

buglist6.00 buglist6.00a buglist6.00ax fixlist7.00

Summary:

SYMPTOMS

In Microsoft C versions 6.0, 6.0a, and 6.0ax, the mktime() function

is documented as returning a -1 if the date in the tm structure was

before 1980. Actually, a -1 is returned if the date is between 1970

and 1980. If the date is earlier than 1970, an invalid date is

returned.

This problem also occurs with the mktime() function supplied with

the Microsoft QuickC Compiler versions 2.5 and 2.51. The sample

code below illustrates this problem.

STATUS

Microsoft has confirmed this to be a problem in C versions 6.0,

6.0a, and 6.0ax and QuickC versions 2.5 and 2.51 (buglist2.50 and

buglist2.51). This problem was corrected in C/C++ version 7.0.

More Information:

Sample Code

-----------

/* Compile options needed: none

*/

#include <time.h>

#include <stdio.h>

#include <sys\types.h>

#include <sys\timeb.h>

#include <string.h>

void main()

{

int c;

struct tm vartime = {0, 0, 6, 16, 7, 0, 0, 0, 1};

for (c = 81; c > 65; c--)

{

vartime.tm_year = c;

printf("Year = %d.\n", c);

if (mktime(&vartime) != (time_t) (-1))

printf("Time entered is %s\n\n", asctime(&vartime));

}

}

Additional reference words: 6.00 6.00a 6.00ax 2.50