Boost logo

Boost Users :

From: Jeff Garland (jeff_at_[hidden])
Date: 2005-07-15 20:01:59


On Fri, 15 Jul 2005 21:46:49 +0400, Serge Skorokhodov wrote
> Hi,
>
> I've built todays cvs boost library but date_time lib seems to have the
> same error as in 1.32 version. That is:
>
> ... snip bug details...

Yeah that's a bug...still. I'll look at it. It may be doubtful for this
release, but see below -- you have more capable options now....
 
> Another question is about wide char support. As far as I understand,
> wstring is supported only through stringstream and facets?

Yes, but the new facets are much better than 1.32. They now support 'format
string' based input and output. Here's how I'd implement your parsing problem
for narrow and wide streams:

  using namespace boost::gregorian;
  using namespace boost::posix_time;
  using namespace std;

  time_input_facet* tf = new time_input_facet();
  //below sets: %Y%m%dT%H%M%S%F for format.
  tf->set_iso_format();
  stringstream ss;
  ss.imbue(std::locale(std::locale::classic(), tf));
  ss.str("20021017T231217.12345");
  ptime pt3;
  ss >> pt3;
  cout << "pt3: " << pt3 << endl;

  wstringstream wss;
  wss.str(L"20021017T231217.12345");
  
  //this time we'll set the format
  wtime_input_facet* wtif = new wtime_input_facet(L"%Y%m%dT%H%M%S%F");
  // wtif->set_iso_format(); <-- this works too...
  wss.imbue(std::locale(std::locale::classic(), wtif));
  ptime pt4;
  wss >> pt4;

  wtime_facet* wtf = new wtime_facet();
  wtf->set_iso_format();
  wcout.imbue(std::locale(std::locale::classic(), wtf));
  wcout << "pt4: " << pt4 << endl;

Output is:

pt3: 2002-Oct-17 23:12:17.123450
pt4: 20021017T231217.123450

You can read more in the 1.33 docs at:

http://engineering.meta-comm.com/resources/cs-win32_metacomm/doc/html/date_time/date_time_io.html

or download in pdf form:

http://www.crystalclearsoftware.com/libraries/date_time/date_time.pdf

Jeff

ps: Make sure you update your CVS -- I just fixed a bug that impacted input
parsing...


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net