[Boost-users] [date_time] binary serialization / integer representation

76 views
Skip to first unread message

Rutger ter Borg

unread,
Oct 21, 2009, 5:18:13 AM10/21/09
to boost...@lists.boost.org

Hello,

I would like to serialize date_time types to a binary archive, and/or
convert them to, say, a integer types. I see the counted time system does
use a 64 bit integer for ptime, but doesn't provide access to it.

Is there something available for this use, or should I create a conversion
function?

Thanks in advance,
Cheers,

Rutger

_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Igor R

unread,
Oct 21, 2009, 5:28:54 AM10/21/09
to boost...@lists.boost.org
I would like to serialize date_time types to a binary archive, and/or
convert them to, say, a integer types. I see the counted time system does
use a 64 bit integer for ptime, but doesn't provide access to it.

Is there something available for this use, or should I create a conversion
function?
 
 

#include <boost/date_time/posix_time/time_serialize.hpp>

Rutger ter Borg

unread,
Oct 21, 2009, 5:45:03 AM10/21/09
to boost...@lists.boost.org
Igor R wrote:
>
> #include <boost/date_time/posix_time/time_serialize.hpp>
>

Thanks, I am aware of the current serialization support of ptime objects. As
far as the docs go, it supports text and xml archives.

However, I'm not that interested in (de)serializing to a variable amount of
bytes where 8 bytes would be more than sufficient, please see attached. I'm
particularly interested in efficient binary serialization of date_time types
and/or conversion to integer(s).

Cheers,

Rutger

test.cpp

Igor R

unread,
Oct 21, 2009, 6:03:49 AM10/21/09
to boost...@lists.boost.org
> I'm particularly interested in efficient binary serialization of date_time types and/or conversion to integer(s).
 
 
I also can't see any access to the internal value, so what you can do instead is to make some time_duration, and use it instead of the absolute ptime. Like this:
 
 pt::ptime epoch(greg::date(1970, 1, 1));  // or some other reference point
 pt::time_duration duration = t - epoch;
 boost::int64_t diff = duration.total_seconds(); // or total_microseconds() or ticks()
Similarly, you can reconstruct the ptime later.

Rutger ter Borg

unread,
Oct 21, 2009, 1:30:28 PM10/21/09
to boost...@lists.boost.org

Igor R wrote:
>
> I also can't see any access to the internal value, so what you can do
> instead is to make some time_duration, and use it instead of the absolute
> ptime. Like this:
>
> pt::ptime epoch(greg::date(1970, 1, 1)); // or some other reference
> point pt::time_duration duration = t - epoch;
> boost::int64_t diff = duration.total_seconds(); // or
> total_microseconds()
> or ticks()
> Similarly, you can reconstruct the ptime later.

Thanks, it comes close to a solution, it would take some more work to
represent special values. It is kind of reimplementing the counted time
system stuff :-/ Perhaps a memcpy() of a ptime will do the trick, too.

Reply all
Reply to author
Forward
0 new messages