|
Boost Users : |
From: Jeff Garland (jeff_at_[hidden])
Date: 2006-10-01 22:31:31
Sean Huang wrote:
> ----- Original Message -----
> From: "Jeff Garland" <jeff_at_[hidden]>
> To: <boost-users_at_[hidden]>
> Sent: Sunday, October 01, 2006 8:03 PM
> Subject: Re: [Boost-users] [date_time]time zone input
>
>
>>> That would be great. What we are trying to do is to convert DICOM DT
>>> (Date
>>> time) element to boost::date_time and it is in the format shown below:
>>> YYYYMMDDHHMMSS.FFFFFF&ZZZZ
>>> One way I can think of is treat the string as posix time and parse the
>>> time-zone offset part ourselves. It sounds like there are better ways to
>>> accomplish this. I would appreciate it very much if you could point me to
>>> the right direction.
>> That's exactly what I would suggest, although actually you can probably
>> parse
>> it into a time_duration.
> Can you elaborate on this a bit more?
See below.
> I just use it to do a one-time adjustment. I agree with you that the
> aforemented format does not fully specify a time zone (I guess I used the
> wrong subject in the first place. :-)). DICOM only uses the ZZZZ as the
> offset from UTC and that's how we plan to use ZZZZ. We'll convert it to UTC
> time as soon as it is parsed.
Ok, easy as pie. We'll set the time_duration_format format, stream it in and
convert to utc:
try {
//setup your input facet
time_input_facet *facet = new time_input_facet();
facet->set_iso_format();
facet->time_duration_format("%H%M"); // just get a tz parts
some_stream_instance.imbue(std::locale(std::locale::classic(), facet));
//stream the parts in
ptime t;
time_duration td(0,0,0);
//get the time part
t >> some_stream_instance;
//now get the utc offset
td >> some_stream_instance;
t += td; //convert time to UTC
}
catch(std::exception& e)
I didn't compile or run this...you'll what some error handling...but I'm 99%
sure it will do what you want :-)
Jeff
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net