Bug #2031

mktime and timegm are broken

Added by alexh about 3 years ago. Updated about 3 years ago.

Status:ClosedStart date:
Priority:HighDue date:
Assignee:-% Done:

0%

Category:-
Target version:-

Description

Both mktime and timegm are broken. They seem to always return -1 while any other
system with the same code returns the correct result.

This must have been broken for years, since no recent changes look suspicious.

Test case:

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

int main(void) {
struct tm tm;
time_t gm_time;

memset(&tm, 0, sizeof(struct tm));
tm.tm_sec = 20;
tm.tm_min = 1;
tm.tm_hour = 3;
tm.tm_mday = 15;
tm.tm_mon = 12;
tm.tm_year = 2010;

gm_time = mktime(&tm);
printf("Time is: %d\n", gm_time);
return 0;
}

History

#1 Updated by alexh about 3 years ago

mea culpa, tm_year needs to be 2010 - 1900. closing this :)

Also available in: Atom PDF