Boost conversion to struct tm for version 1.31
Hi all, I need some help converting a boost::gregorian::date to struct tm in version 1.31. to_tm(date) function dont seems to work in this version. Your help is greatly appreciated. Thanks Debayan
debayan.bhattacharya@firstinvestors.com wrote:
Hi all,
I need some help converting a boost::gregorian::date to struct tm in version 1.31. to_tm(date) function dont seems to work in this version.
Your help is greatly appreciated.
I believe that function was added in 1.32. Here's how it's done: //! Converts a date to a tm struct. Throws out_of_range exception if date is a special value inline std::tm to_tm(const boost::gregorian::date& d) { if(d.is_pos_infinity() || d.is_neg_infinity() || d.is_not_a_date()){ std::string s("tm unable to handle date value of " + to_simple_string(d)); throw std::out_of_range(s); } std::tm datetm; boost::gregorian::date::ymd_type ymd = d.year_month_day(); datetm.tm_year = ymd.year-1900; datetm.tm_mon = ymd.month-1; datetm.tm_mday = ymd.day; datetm.tm_wday = d.day_of_week(); datetm.tm_yday = d.day_of_year()-1; datetm.tm_hour = datetm.tm_min = datetm.tm_sec = 0; datetm.tm_isdst = -1; // negative because not enough info to set tm_isdst return datetm; } Jeff
participants (2)
-
debayan.bhattacharyaï¼ firstinvestors.com
-
Jeff Garland