public inbox for glibc-bugs@sourceware.org help / color / mirror / Atom feed
From: "yofuh at bosng dot de" <sourceware-bugzilla@sourceware.org> To: glibc-bugs@sources.redhat.com Subject: [Bug libc/2483] New: mktime normalizes wrong Date: Fri, 24 Mar 2006 19:12:00 -0000 [thread overview] Message-ID: <20060324191159.2483.yofuh@bosng.de> (raw) 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.
next reply other threads:[~2006-03-24 19:12 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2006-03-24 19:12 yofuh at bosng dot de [this message] 2006-05-06 6:42 ` [Bug libc/2483] " drepper at redhat dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20060324191159.2483.yofuh@bosng.de \ --to=sourceware-bugzilla@sourceware.org \ --cc=glibc-bugs@sources.redhat.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).