Opened 16 years ago

Closed 16 years ago

#622 closed Bugs (Wont Fix)

time_from_string silently misreads date

Reported by: nobody Owned by: az_sw_dude
Milestone: Component: date_time
Version: None Severity:
Keywords: Cc:

Description

The following code snippet:

       boost::posix_time::ptime t3
            = boost::posix_time::time_from_string
            ("2006-03-02");
       cout << " t3 = " <<
           boost::posix_time::to_simple_string(t3)
           << endl;

Gives:

              t3 = 2006-May-24 14:03:02

Admittedly, the date-time string is misformatted,
as it doesn't have the HH-MM-SS fields, but
silently giving the wrong dete is likely
to be a very serious problem to users.

For the record, let me say that date_time
and boost is general are really very fine
work which I greatly appreciate.

   -Mike Albert
  MAlbert@princeton.com

Change History (2)

comment:1 by az_sw_dude, 16 years ago

Logged In: YES 
user_id=579686

Hi Mike --

Have you considered using the new streaming i/o system
instead of the from_string calls? The new i/o framework has
much better error handling than the time_from_string calls.
 Basically you can recode your example this way:

std::stringstream ss("2006-03-02"))
ptime t;
ss >> t; //throws bad month

At the moment I'm not terribly inclined to try and fix the
older parsers as I plan to eventually replace them with
stringstream code under the hood.

Jeff

comment:2 by Gennaro Prota, 16 years ago

Status: assignedclosed
Note: See TracTickets for help on using tickets.