From: Spider Boardman Date: Wed, 30 Sep 1998 15:12:09 +0000 (-0400) Subject: normalize tm struct passed to strftime() with mktime() X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e44f695ee9be4f523999589b52c7c8e9ddc1bed9;p=p5sagit%2Fp5-mst-13.2.git normalize tm struct passed to strftime() with mktime() Message-Id: <199809301912.PAA26119@Orb.Nashua.NH.US> Subject: [PATCH 5.005_52] Re: POSIX::strftime returns incorrect date p4raw-id: //depot/perl@1914 --- diff --git a/ext/POSIX/POSIX.pod b/ext/POSIX/POSIX.pod index 4726487..6a4a61a 100644 --- a/ext/POSIX/POSIX.pod +++ b/ext/POSIX/POSIX.pod @@ -1009,13 +1009,14 @@ Convert date and time information to string. Returns the string. Synopsis: - strftime(fmt, sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0) + strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1) The month (C), weekday (C), and yearday (C) begin at zero. I.e. January is 0, not 1; Sunday is 0, not 1; January 1st is 0, not 1. The -year (C) is given in years since 1900. I.e. The year 1995 is 95; the +year (C) is given in years since 1900. I.e., the year 1995 is 95; the year 2001 is 101. Consult your system's C manpage for details -about these and the other arguments. +about these and the other arguments. The given arguments are made consistent +by calling C before calling your system's C function. The string for Tuesday, December 12, 1995. diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs index 6958c00..1840ca4 100644 --- a/ext/POSIX/POSIX.xs +++ b/ext/POSIX/POSIX.xs @@ -3591,7 +3591,7 @@ mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0) RETVAL char * -strftime(fmt, sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0) +strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1) char * fmt int sec int min @@ -3617,6 +3617,7 @@ strftime(fmt, sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0) mytm.tm_wday = wday; mytm.tm_yday = yday; mytm.tm_isdst = isdst; + (void) mktime(&mytm); len = strftime(tmpbuf, sizeof tmpbuf, fmt, &mytm); ST(0) = sv_2mortal(newSVpv(tmpbuf, len)); }