Boost logo

Boost Users :

From: Jeff Garland (jeff_at_[hidden])
Date: 2006-10-01 23:40:39


Sean Huang wrote:
> ----- Original Message -----
> From: "Jeff Garland" <jeff_at_[hidden]>
> To: <boost-users_at_[hidden]>
> Sent: Sunday, October 01, 2006 10:31 PM
> Subject: Re: [Boost-users] [date_time]time zone input
>
>
>> 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 :-)
>>
> I actually thought about this but encountered a problem with the sign part
> (for example, +05:00). According to the documentation, "%+" and "%-" only
> work for output. I just tried again and got an exception (with 1.33). Maybe
> I am missing something here...

Oh crud...that's not good. That needs to be fixed for sure...

> In any rate, it is easy to parse the offset part ourselves.

Yep.

> Again, thank you very much for your help!

Sure thing :-)

> By the way, shouldn't it be t-=td?

No, b/c I was expecting the sign to be pulled out by the streaming operator.
So if it is -0700 and you add it will go back from UTC. Similarly if it's
+0700 it also does the right thing. Basically, you don't want to change the
sign by subtracting.

So in your parsing code you'll have to pull out the sign and then subtract or
add as appropriate.

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