# HG changeset patch # User John W. Eaton # Date 1291880241 18000 # Node ID f286a874617c95029e1d93ba5f3b9288b283bc5b # Parent ef0e995f8c0ff9e0ac106c315efe36bf0f39bbcc datestr: handle dates before 1970-01-01 diff -r ef0e995f8c0f -r f286a874617c scripts/ChangeLog --- a/scripts/ChangeLog Thu Dec 09 01:15:30 2010 -0500 +++ b/scripts/ChangeLog Thu Dec 09 02:37:21 2010 -0500 @@ -1,3 +1,8 @@ +2010-12-09 John W. Eaton + + * time/datestr.m: Don't call localtime (mktime (tm)) to fill in + missing elements of time strcture. + 2010-12-08 Ben Abbott * plot/fill.m: Fix bug that implies nextplot = "add". diff -r ef0e995f8c0f -r f286a874617c scripts/time/datestr.m --- a/scripts/time/datestr.m Thu Dec 09 01:15:30 2010 -0500 +++ b/scripts/time/datestr.m Thu Dec 09 02:37:21 2010 -0500 @@ -247,7 +247,8 @@ df = regexprep (df, '[Dd][Dd]', "%d"); - tmp = names_d{weekday (datenum (v(i,1), v(i,2), v(i,3)))}; + wday = weekday (datenum (v(i,1), v(i,2), v(i,3))); + tmp = names_d{wday}; df = regexprep (df, '([^%])[Dd]', sprintf ("$1%s", tmp)); df = regexprep (df, '^[Dd]', sprintf ("%s", tmp)); @@ -277,10 +278,14 @@ sec = vi(6); tm.sec = fix (sec); tm.usec = fix (rem (sec, 1) * 1e6); - ## Force mktime to check for DST. - tm.isdst = -1; - - str = strftime (df, localtime (mktime (tm))); + tm.wday = wday - 1; + ## FIXME -- Do we need YDAY and DST? How should they be computed? + ## We don't want to use "localtime (mktime (tm))" because that + ## doesn't correctly handle dates before 1970-01-01 on some systems. + ## tm.yday = ?; + ## tm.isdst = ?; + + str = strftime (df, tm); if (i == 1) retval = str;