Topic: Discussion: time_get


Author: sirwillard@my-deja.com
Date: 2000/01/19
Raw View
I've recently had the need to do some date/time formatting that needed
to be locale independent.  Knowing that the C++ standard was supposed
to address this I quickly jumped in feet first learning the facets
std::time_put and std::time_get.  Except for a bug in the
implementation available to me (actually, a bug in the MS C-RTL that
propagated to the Dinkumware implementation of the C++ STD library)
time_put works wonderfully.  Well, at least as wonderfully as the C
formatting capabilities.  There's a few niceties I'd like above and
beyond what's available, but that's nit-picking.  However, the time_get
facet leaves a lot to be desired.

The time_put facet lets us format a date in near infinite ways.  Using
a simple format string like you do with the C routine strftime you can
format a date in any way you like.  Unfortunately, time_get doesn't
really perform the inverse of time_put.  The format must be in a pretty
standard form in order to input the value easily.  One could argue that
enough capability exists to write higher level routines to manage to
parse any date/time, but in all honesty, this is VERY difficult to do
with out a timepunct class, which is mysteriously missing from the
standard.

The folks at CodeWarrior are the only ones I've found on the net who've
talked about a timepuct class.  They claim it's such as common
extension that it may as well be part of the standard.  Nice idea, but,
again, they seem to be the only ones who've added this extension making
the statement kind of silly.  Further, even if everyone were to add
this extension, they'd probably all define it differently since there
is no standard.  So my biggest question is why timepunct wasn't
included in the standard to begin with?  The other question would be,
why isn't time_get a true inverse of time_put, like all the other
get/put facets are?

In any event, does anyone know of code that attempts to allow
date/times to be parsed according to locale information as well as a
format string ala strftime?  Bjarne Stroustrup at least started to make
time_get more useful in his Appendix D, Locales (not part of the book,
but available on the web... sorry, I've misplaced the URL), but his
code is barely even a start on "fixing" what I see as a very broken
facet (at least not useable for anything but the most trivial of time
inputs).

--
William E. Kempf
Software Engineer, MS Windows Programmer


Sent via Deja.com http://www.deja.com/
Before you buy.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]