From: Gurusamy Sarathy <gsar@cpan.org>
Date: Sat, 19 Feb 2000 16:10:37 +0000 (+0000)
Subject: POSIX::strftime gets the date wrong (from John Tobey
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d0e85dcee87ca227273fd34b9a90f68c96b3d833;p=p5sagit%2Fp5-mst-13.2.git

POSIX::strftime gets the date wrong (from John Tobey
<jtobey@epsilondev.com>)

p4raw-id: //depot/perl@5145
---

diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs
index af43c40..3a523d1 100644
--- a/ext/POSIX/POSIX.xs
+++ b/ext/POSIX/POSIX.xs
@@ -510,8 +510,14 @@ mini_mktime(struct tm *ptm)
 	}
     }
     ptm->tm_year = year - 1900;
-    ptm->tm_mon = month;
-    ptm->tm_mday = yearday;
+    if (yearday) {
+      ptm->tm_mday = yearday;
+      ptm->tm_mon = month;
+    }
+    else {
+      ptm->tm_mday = 31;
+      ptm->tm_mon = month - 1;
+    }
     /* re-build yearday based on Jan 1 to get tm_yday */
     year--;
     yearday = year*DAYS_PER_YEAR + year/4 - year/100 + year/400;
diff --git a/t/lib/posix.t b/t/lib/posix.t
index 10c06be..abc4563 100755
--- a/t/lib/posix.t
+++ b/t/lib/posix.t
@@ -14,7 +14,7 @@ use POSIX qw(fcntl_h signal_h limits_h _exit getcwd open read strftime write);
 use strict subs;
 
 $| = 1;
-print "1..26\n";
+print "1..27\n";
 
 $Is_W32 = $^O eq 'MSWin32';
 
@@ -121,6 +121,7 @@ try_strftime(23, "Mon Mar 01 00:00:00 1999 060", 0,0,24, 28,1,99);
 try_strftime(24, "Mon Feb 28 00:00:00 2000 059", 0,0,0, 28,1,100);
 try_strftime(25, "Tue Feb 29 00:00:00 2000 060", 0,0,0, 0,2,100);
 try_strftime(26, "Wed Mar 01 00:00:00 2000 061", 0,0,0, 1,2,100);
+try_strftime(27, "Fri Mar 31 00:00:00 2000 091", 0,0,0, 31,2,100);
 &POSIX::setlocale(&POSIX::LC_TIME, $lc) if $Config{d_setlocale};
 
 $| = 0;