|
Boost : |
From: Philip Miller (pwmiller_at_[hidden])
Date: 2003-06-26 16:16:59
Yes, that helps. Of course, it would be nice to have the time_from_string use its
internal month table to turn the month string into the correct integer. ;-)
If/when I have time, I may look into how to do that. I think it would also be
nice to be able to configure (at compile time and/or at run time) the format the
date_time library uses for its simple format. One choice might be an additonal
(default?) argument to to_simple_string. Please keep in mind that these are only
suggestions regarding relatively minor nitpicks in what I consider to be a great
library. If I am not yet annoying you with my pestering questions, could you
point me in the right direction on how I might go about solving the problem with
the operator<< and a default facet?
Thanks for your help.
Phil
P.S. Here is my attempt (approach number 1) at solving the problem. I modified
date_format_simple.hpp and date_names_put.hpp so that each chooses
month_as_integer as the hard-wired month_format to return. Any chance on getting
these changes into the next date_time library? :-)
Thus, I have changed simple_format::month_format to be
//! Describe month format
static month_format_spec month_format()
{
// return month_as_short_string;
return month_as_integer;
}
and date_names_put::do_month_format to be
//! Default month format
virtual month_format_spec do_month_format() const
{
// return month_as_short_string;
return month_as_integer;
}
Jeff Garland wrote:
> On Thu, 26 Jun 2003 14:35:26 -0400, Philip Miller wrote
> > I am trying out the boost 1.30.0 date_time library and am quite pleased
> > with it. I just came across a "feature" on which I would appreciate
> > some help. There is an asymmetry when converting a ptime to/from a
> > simple string. The to_simple_string(ptime) method will output
> > 2002-Jan-01 10:00:01.123456789 but the time_from_string( const
> > std::string& ) methhod will choke on "Jan". Is this a bug or a
> > feature? I would like a symmetric pair of functions such that the
> > following code works and t1 == t0.
> >
> > t1 = time_from_string( to_simple_string( t0 ) )
> >
> > I appreciate any feedback.
>
> Well, I guess it is a feature :-(
>
> Apparently there is no existing set of to_string/from functions that
> offer this functionality directly. So in the short run your
> options are:
>
> 1) write your own version of to_string which is compatible
> 2) Use operator<< with an appropriate date formmatting facet
>
> Number 1 would be something like:
> //WARNING -- never compiled or tested!!
> std::string another_to_string(const boost::posix_time::ptime& t) {
> using boost::gregorian;
> date d = t.get_date();
> std::string s =
> date_time::date_formatter<date,date_time::iso_extended_format>::date_to_string
> (t.get_date());
> s = s + ' ' + boost::posix_time::to_iso_string(t.time_of_day());
> return s;
> }
>
> HTH,
>
> Jeff
> }
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk