[date_time] Constructing a ptime with __int64

Hi there, is it possible to construct a ptime with an __int64. The internal representation is of the same type. I couldn't find anything on this issue. Thanks in advance, Christian

On Mon, 30 Jan 2006 19:00:09 -0500, Christian Henning wrote
Hi there, is it possible to construct a ptime with an __int64. The internal representation is of the same type. I couldn't find anything on this issue.
I don't think I recommend it and haven't tried it recently, but it appears that it's possible. See: http://www.boost.org/doc/html/ptime.html ptime(const time_rep_type &); I don't recommend it because of the obvious violation of encapsulation and the fact that if you recompile with the 96 bit internal representation your code will break. Oh, and if you want it to be portable, you should use boost::int64_t instead of __int64. Jeff

Seems to be broken on my machine: boost::int64_t nTime = 3434; ptime oTestTime( nTime ); will result in: error C2664: 'boost::posix_time::ptime::ptime(boost::gregorian::date)' : cannot convert parameter 1 from 'boost::int64_t' to 'boost::gregorian::date' Constructor for class 'boost::gregorian::date' is declared 'explicit' I'm using MSVC 7.1 and boost 1.33.1 . In any event shouldn't a change of the internal representation 64bit -> 96bit result in an compiler error, when I use "ptime(const time_rep_type &)"? Thanks, Christian

On Tue, 31 Jan 2006 10:06:00 -0500, Christian Henning wrote
Seems to be broken on my machine:
boost::int64_t nTime = 3434; ptime oTestTime( nTime );
will result in:
error C2664: 'boost::posix_time::ptime::ptime(boost::gregorian::date) ' : cannot convert parameter 1 from 'boost::int64_t' to 'boost::gregorian::date' Constructor for class 'boost::gregorian::date' is declared 'explicit'
I'm using MSVC 7.1 and boost 1.33.1 .
This will compile with gcc on Linux: boost::int64_t n = 1138736958000000LL; ptime::time_rep_type val(n); ptime t2(val); but it aborts with a bad_year exception. I didn't really track down why. I've made this hard to do for good reason -- why are you trying to do this again? What is the problem that makes you want to use the internal value? Not that you can't get the value out either...
In any event shouldn't a change of the internal representation 64bit -> 96bit result in an compiler error, when I use "ptime(const time_rep_type &)"?
Yes probably -- but if not it would be a runtime discovery of incorrect results. Jeff

This will compile with gcc on Linux: boost::int64_t n = 1138736958000000LL;
ptime::time_rep_type val(n); ptime t2(val);
This will also compile on Windows with VC 7.1.
but it aborts with a bad_year exception. I didn't really track down why.
At the construction no exception will occur. But when I do: to_simple_string( t2 ) I will get an "Unknown exception". It's thrown at gregorian_calendar.ipp[122], since the year is negative. I have no idea how this can happen.
I've made this hard to do for good reason -- why are you trying to do this again? What is the problem that makes you want to use the internal value? Not that you can't get the value out either...
I was just thinking of how to store the time value in a database. It seems to me that this would be the most efficient way of saving a time. On this other hand when things change, like the internal representation code will most likely break. So, I decided to store a string, instead. Thanks for the help. Christian
participants (2)
-
Christian Henning
-
Jeff Garland