Subtracting months / years with boost :: posix_time :: ptime

I have boost::posix_time::ptimeone that points March 31st 2010like this:

ptime p(date(2010, Mar, 31));

I would like to deduct the month (and possibly years) from that date. From the documents I see these two operators: ptime operator-(time_duration)and ptime operator-(days), but none of them can work with months / years. If I try to do:

time_duration duration = hours(24 * 30);
ptime pp = p - duration;

I get March 1st, and if I try:

ptime pp = p - days(30);

I still get March 1st, and I want to get February 28th.
How can I achieve the desired result? (I would like to get the desired result when subtracting the month from March 28, 29, 30).

+3
source share
2 answers
Operator

boost:: posix_time:: ptime:: date() . greg_year, greg_month .. .

+4

, , , 30 , 30 .

, " ".

0

Source: https://habr.com/ru/post/1737920/


All Articles