[date_time] posix_time input/output facet symmetry

I'm experiencing a problem using custom formatting of fractional seconds.
const std::string date_string = "2006 Jun 01 999000 23.59.59";
const std::string format_string = "%Y %b %d %f %H.%M.%S";
When using a time_facet together with the "%f" flag, I get a correct output
containing a 6-digit number in place of the fractional part.
However, using a time_input_facet together with the "%f" flag, I cannot get
a correct ptime from an input using the same format as the above example.
The problem is twofold :
1) First, the input facet expects a leading '.'
otherwise, it parses a special value and fails.
[see time_facet.hpp(1035-1049)]
This is not the case in an output facet.
2) Second, even if I include a leading dot, the space
after the fractional seconds is not consumed, and
the parsing of the remainder fails.
This means that I need to add an extra space to the
input format string.
Here is a sample program:
---------
#include <cassert>
#include

LABELLE, Maxime wrote:
I'm experiencing a problem using custom formatting of fractional seconds.
const std::string date_string = "2006 Jun 01 999000 23.59.59"; const std::string format_string = "%Y %b %d %f %H.%M.%S";
When using a time_facet together with the "%f" flag, I get a correct output containing a 6-digit number in place of the fractional part.
However, using a time_input_facet together with the "%f" flag, I cannot get a correct ptime from an input using the same format as the above example.
...snip detail...
Am I missing something ?
No, I'm afraid this is a parser bug. I've put together a fix I'd like you to try out. I don't believe it's 100% generalized yet, but I believe it fixes your issue and doesn't break any of the current regression tests. Download it from http://boost-consulting.com/vault/index.php under date_time -- time_facet.hpp and patch it into your boost/date_time/ directory. Thanks, Jeff
participants (2)
-
Jeff Garland
-
LABELLE, Maxime