[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: datestr (datenum (1969, 1, 1), 0) does not work on octave-3.3.51+ on
From: |
John W. Eaton |
Subject: |
Re: datestr (datenum (1969, 1, 1), 0) does not work on octave-3.3.51+ on MinGW |
Date: |
Thu, 18 Nov 2010 15:22:15 -0500 |
On 18-Nov-2010, Philip Nienhuis wrote:
| JWE has suggested to fix mktime() in gnulib.
| Based on googling for mktime() I get the impression that mktime() is so
| deeply entangled in OS libraries and so strongly tied to number of seconds
| since some epoch (-date) that in practice this may be an unreachable goal.
| (But OK, I'm guessing.)
|
| Perhaps Octave might be better off with a solution that doesn't involve
| time() or mktime() at all. FWIW, That Other Program's datestr.m invokes a
| mex file that takes care of converting datenum (-arrays) into a struct
| similar to that returned by localtime(). AFAICS that mex file doesn't call
| mktime() or time().
OK, if fixing mktime can't work, then it would be fine if we just had
a function that converted a datevec vector to a time structure that
can be passed to strftime. So we just need to convert
vi = v(i,:);
tm.year = vi(1) - 1900;
tm.mon = vi(2) - 1;
tm.mday = vi(3);
tm.hour = vi(4);
tm.min = vi(5);
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)));
to
vi = v(i,:);
tm.year = vi(1) - 1900;
tm.mon = vi(2) - 1;
tm.mday = vi(3);
tm.hour = vi(4);
tm.min = vi(5);
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, tm);
or simply
str = strftime (df, datevec_to_tm_struct (v(i,:));
I think the only reason we really needed localtime (mktime (tm)) was
to normalize everything and check for daylight savings time.
| As my C++ proficiency is negligible I can't suggest a solution, other than
| to use the datestr.m from octave-3.0.3.
I see no problem with having a datevec_to_tm_struct being interpreted.
I don't know how to determine the tm.isdst field, but I guess that we
just need to do whatever the localtime function from the C library
does for that. It should be relatively easy to ensure that the tm
struct field values are all within range.
jwe
- datestr (datenum (1969, 1, 1), 0) does not work on octave-3.3.51+ on MinGW, Tatsuro MATSUOKA, 2010/11/16
- Re: datestr (datenum (1969, 1, 1), 0) does not work on octave-3.3.51+ on MinGW, Liam Groener, 2010/11/16
- Re: datestr (datenum (1969, 1, 1), 0) does not work on octave-3.3.51+ on MinGW, Tatsuro MATSUOKA, 2010/11/17
- Re: datestr (datenum (1969, 1, 1), 0) does not work on octave-3.3.51+ on MinGW, Philip Nienhuis, 2010/11/18
- Re: datestr (datenum (1969, 1, 1), 0) does not work on octave-3.3.51+ on MinGW,
John W. Eaton <=
- Re: datestr (datenum (1969, 1, 1), 0) does not work on octave-3.3.51+ on MinGW, Tatsuro MATSUOKA, 2010/11/29
- Re: datestr (datenum (1969, 1, 1), 0) does not work on octave-3.3.51+ on MinGW, Philip Nienhuis, 2010/11/30