This is sources Bugzilla
Bugzilla Version 2.17.5
Bugzilla Bug 2483
  mktime normalizes wrong Last modified: 2006-05-06 06:42
     Query page      Enter new bug
Bug#: 2483   Hardware:   Reporter: Julian Wiesener <yofuh@bosng.de>
Host: Target: Build:
Product:     Add CC:
Component:   Version:   CC:
Remove selected CCs
Status: RESOLVED   Priority:  
Resolution: INVALID   Severity:  
Assigned To: Ulrich Drepper <drepper@redhat.com>   Target Milestone:  
Flags: Requestee:
  backport ()
  examined ()
  testsuite ()
Summary:
Keywords:

Attachment Description Type Created Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 2483 depends on: Show dependency tree
Show dependency graph
Bug 2483 blocks:

Additional Comments:


Leave as RESOLVED INVALID
Reopen bug
Mark bug as VERIFIED

View Bug Activity   |   Format For Printing


Description:   Last confirmed: 0000-00-00 00:00 Opened: 2006-03-24 19:11
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

------- Additional Comment #1 From Ulrich Drepper 2006-05-06 06:42 -------
This has nothing to do with mktime.  It is strptime which rejects your invalid
data.  This is the correct behavior.

     Query page      Enter new bug
Actions: New | Query | bug # | Reports | Requests   New Account | Log In