|
Boost Users : |
Subject: [Boost-users] [date time] using date_facet to output to a stream once
From: Steve Lorimer (steve.lorimer_at_[hidden])
Date: 2010-06-15 09:38:08
Hi
I have a an object which contains a ptime and an int mask. The mask tells me
that regardless of the value stored inside the ptime object, I should
display the ptime as such.
If you look at the code below (set_fmt function), I set the format of a
date_facet object according to some bitmasks.
I now want to use this date_facet together with my ptime to output the ptime
value to an outputstream?
I don't want it to change the outputstream's settings for ALL ptime values,
just for this single instance
All the examples use a date_facet allocated on the heap, and use
std::cout.imbue(...), whereas I'm looking for functionality similar to
strftime... is this possible?
eg:
class expiration
{
enum expiry_mask
{
expiry_null = 0x00,
expiry_year = 0x01,
expiry_month = 0x02,
expiry_day = 0x04,
expiry_hour = 0x08,
expiry_minute = 0x10,
expiry_second = 0x20,
expiry_date = 0x07, // yyyy/mm/dd
expiry_time = 0x38, // hh:nn:ss
expiry_all = 0x3f // yyyy/mm/dd hh:nn:ss
};
boost::posix_time::ptime desig;
int32_t desig_mask;
boost::gregorian::date_facet fmt;
public:
void expiration::set_fmt(const int32_t mask)
{
switch(mask & expiry_date) *// strip off time part of mask*
{
case expiry_null:
fmt.format("");
break;
case expiry_year | expiry_month | expiry_day: *// display as "**dd
Mmm yy"*
fmt.format("%d %b %y");
break;
case expiry_year | expiry_month: *// display as **"Mmm yy"*
fmt.format("%b %y");
break;
case expiry_year: *// display as "**yy"*
fmt.format("%y");
break;
default:
break;
}
}
... some other stuff here ...
};
Thanks
Steve
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