cvs boost 1.33 date_time problem

Hi, I've built todays cvs boost library but date_time lib seems to have the same error as in 1.32 version. That is: wstring wts = _T("20021017T231217.12345"); wdate_facet* date_facet = new wdate_facet; wtime_facet* time_facet = new wtime_facet; ptime pt1( from_iso_string( convert_string_type<_TCHAR, char>(wts) ) ); long Y = pt1.date().year(); long M = pt1.date().month(); long d = pt1.date().day(); long h = pt1.time_of_day().hours(); long m = pt1.time_of_day().minutes(); long s = pt1.time_of_day().seconds(); long f = pt1.time_of_day().fractional_seconds(); wcout << L"Components of pt1:" << endl << L"Year: " << Y << endl << L"Month: " << M << endl << L"Day: " << d << endl << L"Hours: " << h << endl << L"Minutes: " << m << endl << L"Seconds: " << s << endl << L"Microseconds: " << f << endl; ptime pt2( gregorian::date(2002, 10, 17), posix_time::time_duration(23, 12, 17, 12345) ); wcout << pt2 << endl; Y = pt2.date().year(); M = pt2.date().month(); d = pt2.date().day(); h = pt2.time_of_day().hours(); m = pt2.time_of_day().minutes(); s = pt2.time_of_day().seconds(); f = pt2.time_of_day().fractional_seconds(); wcout << L"Components of pt2:" << endl << L"Year: " << Y << endl << L"Month: " << M << endl << L"Day: " << d << endl << L"Hours: " << h << endl << L"Minutes: " << m << endl << L"Seconds: " << s << endl << L"Microseconds: " << f << endl; Output is: Components of pt1: Year: 2002 Month: 10 Day: 17 Hours: 23 Minutes: 12 Seconds: 17 Microseconds: 0 2002-Oct-17 23:12:17.012345 Components of pt2: Year: 2002 Month: 10 Day: 17 Hours: 23 Minutes: 12 Seconds: 17 Microseconds: 12345 Another question is about wide char support. As far as I understand, wstring is supported only through stringstream and facets? TIA -- Serge

On Fri, 15 Jul 2005 21:46:49 +0400, Serge Skorokhodov wrote
Hi,
I've built todays cvs boost library but date_time lib seems to have the same error as in 1.32 version. That is:
... snip bug details...
Yeah that's a bug...still. I'll look at it. It may be doubtful for this release, but see below -- you have more capable options now....
Another question is about wide char support. As far as I understand, wstring is supported only through stringstream and facets?
Yes, but the new facets are much better than 1.32. They now support 'format string' based input and output. Here's how I'd implement your parsing problem for narrow and wide streams: using namespace boost::gregorian; using namespace boost::posix_time; using namespace std; time_input_facet* tf = new time_input_facet(); //below sets: %Y%m%dT%H%M%S%F for format. tf->set_iso_format(); stringstream ss; ss.imbue(std::locale(std::locale::classic(), tf)); ss.str("20021017T231217.12345"); ptime pt3; ss >> pt3; cout << "pt3: " << pt3 << endl; wstringstream wss; wss.str(L"20021017T231217.12345"); //this time we'll set the format wtime_input_facet* wtif = new wtime_input_facet(L"%Y%m%dT%H%M%S%F"); // wtif->set_iso_format(); <-- this works too... wss.imbue(std::locale(std::locale::classic(), wtif)); ptime pt4; wss >> pt4; wtime_facet* wtf = new wtime_facet(); wtf->set_iso_format(); wcout.imbue(std::locale(std::locale::classic(), wtf)); wcout << "pt4: " << pt4 << endl; Output is: pt3: 2002-Oct-17 23:12:17.123450 pt4: 20021017T231217.123450 You can read more in the 1.33 docs at: http://engineering.meta-comm.com/resources/cs-win32_metacomm/doc/html/date_t... or download in pdf form: http://www.crystalclearsoftware.com/libraries/date_time/date_time.pdf Jeff ps: Make sure you update your CVS -- I just fixed a bug that impacted input parsing...

Jeff Garland wrote: I'm not sure that this bug is related to boost::date_time as it occurs in boost::lexical_cast but I encounter it using the last cvs 1.33 version of it.
Another question is about wide char support. As far as I understand, wstring is supported only through stringstream and facets?
Yes, but the new facets are much better than 1.32. They now support 'format string' based input and output. Here's how I'd implement your parsing problem for narrow and wide streams:
using namespace boost::gregorian; using namespace boost::posix_time; using namespace std;
time_input_facet* tf = new time_input_facet(); //below sets: %Y%m%dT%H%M%S%F for format. tf->set_iso_format(); stringstream ss; ss.imbue(std::locale(std::locale::classic(), tf)); ss.str("20021017T231217.12345"); ptime pt3; ss >> pt3; cout << "pt3: " << pt3 << endl;
wstringstream wss; wss.str(L"20021017T231217.12345");
//this time we'll set the format wtime_input_facet* wtif = new wtime_input_facet(L"%Y%m%dT%H%M%S%F"); // wtif->set_iso_format(); <-- this works too... wss.imbue(std::locale(std::locale::classic(), wtif)); ptime pt4; wss >> pt4;
wtime_facet* wtf = new wtime_facet(); wtf->set_iso_format(); wcout.imbue(std::locale(std::locale::classic(), wtf)); wcout << "pt4: " << pt4 << endl;
This code does not complie with MSVC++.NET 2003 with the following error:
c:\usr\include\boost-1_33\boost\lexical_cast.hpp(150) : error C2679:
binary '<<' : no operator found which takes a right-hand operand of type
'const NewSource' (or there is no acceptable conversion)
c:\usr\include\boost-1_33\boost\lexical_cast.hpp(149) : while
compiling class-template member function 'bool
boost::detail::lexical_stream

On Sun, 17 Jul 2005 23:42:56 +0400, Serge Skorokhodov wrote
Jeff Garland wrote:
I'm not sure that this bug is related to boost::date_time as it occurs in boost::lexical_cast but I encounter it using the last cvs 1.33 version of it.
Well, it's related to the extent that it prevents date-time from working...
This code does not complie with MSVC++.NET 2003 with the following error:
c:\usr\include\boost-1_33\boost\lexical_cast.hpp(150) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const NewSource' (or there is no acceptable conversion) c:\usr\include\boost-1_33\boost\lexical_cast.hpp(149) : while compiling class-template member function 'bool boost::detail::lexical_stream
::operator <<(const Source &)' with [ ] c:\usr\include\boost-1_33\boost\lexical_cast.hpp(150) : error C2228: left of '.fail' must have class/struct/union type The problem seems to be too deep in the library for me:(
This is VC7 I presume? I'm afraid that the new i/o code is incompatible with VC7, for a variety of reasons, and I have no intent to try and support it. Anyway, I may be able to fix the other parsing bug in time for 1.33, but that won't help you with wide chars... Jeff

Jeff Garland wrote:
This is VC7 I presume? I'm afraid that the new i/o code is incompatible with VC7, for a variety of reasons, and I have no intent to try and support it. Anyway, I may be able to fix the other parsing bug in time for 1.33, but that won't help you with wide chars...
Not exactly, it's VC7.1. It's a pity if new boost will be not compatible with a major Win32 compiler:( I'll try to compile the tests for date_time and see what happen. By the way, implicit_cast test failed to compile with vc-7_1 tool:( I guess that wchar support is not crucial for my purpose anyway 'cause I do not need any days of week etc.;) The problem is that the data is always in UTF-16 in Windows COM;)) Thanks for your effort -- Serge

On Mon, 18 Jul 2005 01:28:17 +0400, Serge Skorokhodov wrote
Jeff Garland wrote:
Not exactly, it's VC7.1. It's a pity if new boost will be not compatible with a major Win32 compiler:( I'll try to compile the tests for date_time and see what happen. By the way, implicit_cast test failed to compile with vc-7_1 tool:(
Sorry, VC 7_1 should be ok -- as I recall now there was lexical cast problem that was in CVS a week or 2 back and has since been fixed. Are you totally up to date? If you look at the regression tests you will see date-time is at 100% with vc 7_1. Bottom line, it should work.
I guess that wchar support is not crucial for my purpose anyway 'cause I do not need any days of week etc.;) The problem is that the data is always in UTF-16 in Windows COM;))
Don't give up yet...
Thanks for your effort
You're welcome. Jeff

Hi, <skip> Jeff Garland wrote:
This is VC7 I presume? I'm afraid that the new i/o code is incompatible with VC7, for a variety of reasons, and I have no intent to try and support it. Anyway, I may be able to fix the other parsing bug in time for 1.33, but that won't help you with wide chars...
<skip> I've found why it didn't work. Visual C++ has a compiler setting that force the compiler to treat wchar_t as a built-in compiler type instead of a typedef of short. Everything compiles and works perfectly with this setting (/Zc:wchar_t). Well, except of being the right thing it may be not very good for some Win32 API functions that seem to prefer to work with wchars as shorts:( Another question though:) ptime::hours() etc ruturn an extreamly lengthy typedef instead of long. Is it possible to "export" this typedef somehow in the library? Just to save a little bit typing? :))) -- Serge

On Mon, 18 Jul 2005 02:20:24 +0400, Serge Skorokhodov wrote
Another question though:)
ptime::hours() etc ruturn an extreamly lengthy typedef instead of long. Is it possible to "export" this typedef somehow in the library? Just to save a little bit typing? :)))
You can use time_duration::hour_type -- is that what you mean? Jeff

Jeff Garland wrote:
On Mon, 18 Jul 2005 02:20:24 +0400, Serge Skorokhodov wrote
Another question though:)
ptime::hours() etc ruturn an extreamly lengthy typedef instead of long. Is it possible to "export" this typedef somehow in the library? Just to save a little bit typing? :)))
You can use time_duration::hour_type -- is that what you mean?
I think so and try it asap:) thank you. -- Serge

Jeff Garland wrote:
On Mon, 18 Jul 2005 02:20:24 +0400, Serge Skorokhodov wrote
Another question though:)
ptime::hours() etc ruturn an extreamly lengthy typedef instead of long. Is it possible to "export" this typedef somehow in the library? Just to save a little bit typing? :)))
You can use time_duration::hour_type -- is that what you mean?
Thanks a lot for both this advice and for bugfix. Everything works OK and I'm nearly happy:) -- Serge

On Fri, 15 Jul 2005 21:46:49 +0400, Serge Skorokhodov wrote
Hi,
I've built todays cvs boost library but date_time lib seems to have the same error as in 1.32 version. That is:
wstring wts = _T("20021017T231217.12345"); wdate_facet* date_facet = new wdate_facet; wtime_facet* time_facet = new wtime_facet; ptime pt1( from_iso_string( convert_string_type<_TCHAR, char>(wts) ) ); ... snip more details...
I've checked in a fix for the handling of fractional seconds on from_iso_string. No direct wide char support on that function, but the time should be correct now. Thx for your report. Jeff
participants (2)
-
Jeff Garland
-
Serge Skorokhodov