datestr bug
Rob Mahurin
rob at utk.edu
Wed Jul 23 18:20:59 CDT 2008
On Jul 23, 2008, at 5:47 PM, John W. Eaton wrote:
> On 23-Jul-2008, Rob Mahurin wrote:
>
> | Hello, bug-octave.
> |
> | This statement
> |
> | > str = datestr(day, "yyyy-mm-dd\ndddd\n");
> | > printf(str);
> |
> | seems to do some extra substituting:
> |
> | > 2009-03-14
> | > SaturSay
> |
> | > 2008-11-26
> | > WeWnesWay
> |
> |
> | I'm running 3.0.1
>
> I think this has been reported at least once before. See for example
>
> http://www.nabble.com/datestr-weekday-strptime%2C-2-bugs--
> to7650360.html#a7650360
>
> I'm not sure what the best fix is. I would consider a patch.
It seems like the offending line is
> str = strrep (str, "d", names_d{weekday (datenum (v(i,1), v(i,2), v
> (i,3)))});
in datestr.m, which appears after the "dddd" in-place substitution.
A possibly-good-enough patch would be to follow this with
> # incomplete fix for greedy matching
> str = strrep (str, "SunSay", "Sunday");
> str = strrep (str, "MonMay", "Monday");
> ...
I think the "most correct" way to do this would be a set of regular
expressions to identify the location and type of each format
specifier, followed by a single-pass substitution.
If there were a utility function with the right magic numbers in it I
could use strftime, which has more robust formatting anyway. This:
> printf(strftime ("%A %F %H:%M:%S %Z\n", localtime((now - 719529)
> *24*3600)))
(based on the hint from "help now") seems to go the wrong way from UTC.
Cheers,
Rob
--
Rob Mahurin
Dept. of Physics & Astronomy
University of Tennessee phone: 865 207 2594
Knoxville, TN 37996 email: rob at utk.edu
More information about the Bug-octave
mailing list