I have made some progress, but am now getting unexpected results:
HiI 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/ddexpiry_time = 0x38, // hh:nn:ssexpiry_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 ...
};ThanksSteve