[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Possible bug in os.date when using format qualifiers
- From: Nick Gammon <nick@...>
- Date: Mon, 23 Apr 2007 11:03:15 +1000
Version 5.1.2 introduced a problem when using os.date which was not
present in 5.5.1.
There was a change made in response to a bug I had earlier reported
about an error being reported if os.date was called with an empty
Previously, the string supplied to os.date was passed to strftime in
Now, os.date breaks up the supplied string by looking for %x and
calls strftime for each individual item.
However this breaks the behaviour as described in the Reference
Manual, that the date is "formatted according to the same rules as
the C function strftime".
Depending on which system you run "man strftime" you get slightly
different information, but the gist is that:
"Some conversion specifiers can be modified by preceding them by the
E or O modifier to indicate that an alternative format should be
used.". For example, "%Ec, %EC, %Ex, %EX, %Ry".
Unfortunately the new coding does not allow for the optional letter
between the % and the format specifier.
I also had the idea in my head that you used to be able to do
something like this: os.date ("%#I")
This is supposed to drop leading zeroes. In fact, the MSDN
documentation for strftime mentions exactly that.
I suggest that you do one of:
* revert to a single call of strftime (which would make the function
behave as documented "like strftime"), handling the case of an empty
string as an exception; or
* allow for modifiers "E", "O" and "#" between the % and the format
* modify the documentation to make it clear that only %x is supported
without something between the % and the x - in other words, remove
the reference to "the same rules as ... strftime".
- Nick Gammon