Boost logo

Boost :

Subject: [boost] [date_time] Change to the time_duration default format.
From: Ilya Bobir (ilya.bobir_at_[hidden])
Date: 2009-06-13 18:37:35


Hi all,

I would like to propose a change to the default format for the
time_duration objects. Current format is "%H:%M:%S%f". It does not
allow one to input a time_duration that is longer than 99 hours. My
proposal is to change the format to be "%O:%M:%S%f".

time_duration objects are not restricted to 99 hours so the current
behavior seems to be incorrect.

I have submitted a patch but was told that the change is a braking
change and need to be discussed on a mailing list:
https://svn.boost.org/trac/boost/ticket/1861#comment:3

Please reply if you think there could be issues with the change to the
default time_duration format.

Here is a simple test that shows what I'm talking about:

#include <iostream>
#include <sstream>

#include <boost/date_time.hpp>

using namespace std;
using namespace boost::posix_time;

int main(void)
{
     time_input_facet* facet = new time_input_facet();
     locale loc(locale(locale(), facet));

     time_duration td1(hours(100));
     time_duration td2;

     stringstream ss;
     ss.imbue(loc);

     /* Input using default time_duration format. */

     facet->time_duration_format("%H:%M:%S%f");

     ss << td1;
     ss >> td2;

     cout << td2 << endl;

     /* Input using proposed time_duration format. */

     ss.str("");
     ss.clear();

     facet->time_duration_format("%O:%M:%S%f");

     ss << td1;
     ss >> td2;

     cout << td2 << endl;
}

For me it outputs:

00:00:00
100:00:00

It means that you can not serialize and deserialize arbitrary
time_duration objects if you are using the default format. While the
output facet do write extra digits the input facet will accept only two
digits for the hours field.

Ilya Bobir


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk