Boost logo

Boost Users :

From: Serge Skorokhodov (serge.skorokhodov_at_[hidden])
Date: 2005-08-08 09:45:11


Hi,

In 1.33RC2, the string with wrong formatted date produce wrong
date-time rather than error (vc-7_1):

#include <iostream>
#include <sstream>
#include <string>
#include <stdexcept>
#include "boost/date_time/posix_time/posix_time.hpp"
#include "boost/date_time/posix_time/posix_time_io.hpp"
using namespace std;
using namespace boost::posix_time;
int main()
{
    bool except_fg = false;
    string pts = "2002091";
    istringstream iss(pts);
    iss.exceptions(ios::failbit);
    time_input_facet* tif = new time_input_facet;
    tif->set_iso_format();
    iss.imbue(std::locale(std::locale::classic(), tif));
    ptime pt;
    try
    {
       iss >> pt;
    }
    catch ( const exception& e )
    {
       cout << "Exception reading 2002091: " << e.what() << endl;
       except_fg = true;
    }
    if ( !except_fg )
    {
      cout << "Date-time from 2002091: " << pt << endl;
      except_fg = false;
    }
    pts = "20020913T17043";
    iss.str(pts);
    try
    {
       iss >> pt;
    }
    catch ( const exception& e )
    {
       cout << "Exception reading 20020913T17043: "
       << e.what() << endl;
       except_fg = true;
    }
    if ( !except_fg )
    {
      cout << "Date-time from 20020913T17043: " << pt << endl;
    }
        return 0;
}

Output:

Date-time from 2002091: 2002-Sep-11 00:00:00
Exception reading 20020913T17043: Parse failed. No match found for ''

-- 
Serge

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