converting a timestring to a duration
        Posted  
        
            by radman
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by radman
        
        
        
        Published on 2010-06-07T01:38:51Z
        Indexed on 
            2010/06/07
            1:42 UTC
        
        
        Read the original article
        Hit count: 342
        
Hi,
At the moment I am trying to read in a timestring formatted and create a duration from that. I am currently trying to use the boost date_time time_duration class to read and store the value.
boost date_time provides a method time_duration duration_from_string(std::string) that allows a time_duration to be created from a time string and it accepts strings formatted appropriately ("[-]h[h][:mm][:ss][.fff]".).
Now this method works fine if you use a correctly formatted time string. However if you submit something invalid like "ham_sandwich" or "100" then you will still be returned a time_duration that is not valid. Specifically if you try to pass it to a standard output stream then an assertion will occur.
My question is: Does anyone know how to test the validity of the boost time_duration? and failing that can you suggest another method of reading a timestring and getting a duration from it?
Note: I have tried the obvious testing methods that time_duration provides; is_not_a_date_time(), is_special() etc and they don't pick up that there is an issue.
Using boost 1.38.0
© Stack Overflow or respective owner