This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/2483] New: mktime normalizes wrong
- From: "yofuh at bosng dot de" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: 24 Mar 2006 19:11:59 -0000
- Subject: [Bug libc/2483] New: mktime normalizes wrong
- Reply-to: sourceware-bugzilla at sourceware dot org
mktime should normalize time to the next month if mday is greater than the last
day of the current month.
CTIME(3)
The mktime() function converts a broken-down time structure, expressed
as local time, to calendar time representation. The function ignores
the specified contents of the structure members tm_wday and tm_yday
and recomputes them from the other information in the broken-down time
structure. If structure members are outside their legal interval,
they will be normalized (so that, e.g., 40 October is changed into 9
November). Calling mktime() also sets the external variable tzname
with information about the current time zone. If the specified bro-
ken-down time cannot be represented as calendar time (seconds since
the epoch), mktime() returns a value of (time_t)(-1) and does not
alter the tm_wday and tm_yday members of the broken-down time struc-
ture.
But mktime normalizes wrong, it just delete the last digits until mday is in
legal range, example:
$ cat mktime-test.c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
char str_mday[3] = "00\0";
char date[11] = "00.00.0000\0";
int int_mday = 0;
time_t t = time(NULL);
struct tm *inctime = localtime(&t);
strftime(str_mday, 3, "%e", inctime);
int_mday = atoi(str_mday);
strftime(date, 11, "%e.%m.%Y", inctime);
printf("\ndate: %s\tmday= %d",date,int_mday);
int_mday+=29;
sprintf(str_mday, "%d",int_mday);
strptime(str_mday, "%e", inctime);
t = mktime(inctime);
inctime = localtime(&t);
strftime(date, 11, "%e.%m.%Y", inctime);
printf("\ndate: %s\tmday= %d",date,int_mday);
int_mday+=129;
sprintf(str_mday, "%d",int_mday);
strptime(str_mday, "%e", inctime);
t = mktime(inctime);
inctime = localtime(&t);
strftime(date, 11, "%e.%m.%Y", inctime);
printf("\ndate: %s\tmday= %d",date,int_mday);
int_mday+=4129;
sprintf(str_mday, "%d",int_mday);
strptime(str_mday, "%e", inctime);
t = mktime(inctime);
inctime = localtime(&t);
strftime(date, 11, "%e.%m.%Y", inctime);
printf("\ndate: %s\tmday= %d\n\n",date,int_mday);
return 0;
}
$ gcc -o mktime-test mktime-test.c && ./mktime-test
date: 24.03.2006 mday= 24
date: 5.03.2006 mday= 53
date: 18.03.2006 mday= 182
date: 4.03.2006 mday= 4311
--
Summary: mktime normalizes wrong
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: drepper at redhat dot com
ReportedBy: yofuh at bosng dot de
CC: glibc-bugs at sources dot redhat dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=2483
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.