Boost logo

Boost :

From: William E. Kempf (williamkempf_at_[hidden])
Date: 2002-04-25 09:05:51


----- Original Message -----
From: "Kostya Altukhov" <kostya_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, April 25, 2002 6:41 AM
Subject: Re: [boost] Date/Time formal review

> Mark Rodgers wrote:
>
> >Why not a time_put/strftime pattern string?
> >
> >os << date::set_format( "%B %d,%Y %w %H:%M%:%S" ) << adate;
> >
> I second this. Then there should be similar mechanism to read
> a date from stream according to the pattern string. Something
> similar to strptime function many implementations provide.
>
> In my own home-made date class, I have 'Unformat' function
> that does just that. But it's not based on streams, it works with
> strings.

I've got code that does this using streams. Had to do some tricky things to
determine what the format of %x should be, for example, in a manner that's
portable. This lead me to believe that the date I/O support in C++ is
lacking, severely. So it's an area I'd love to see Boost address, and in
the end be adopted into the standard.

That said... I'm not sure that parsing (reading) of dates should actually
strictly conform to any format string. As long as the strings are never
entered by a human this works, but if you need to allow for human input (and
can't constrain the input with something like a GUI formatted input widget)
then the exact parsing becomes nearly useless. For example, assuming US
conventions, all of the following should be valid date entries:

4-25-02
04-25-02
4-25-2002
04/25/2002
4/25/02

And so on. You get the idea. No matter what the locale used, you're going
to find operators entering dates in all of the above formats (as well as
others). So parsing of dates needs to be a little less strict, IMHO.

Bill Kempf


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