I am trying to calculate the time between two boost::gregorian dates. Currently I am simply taking the difference of the two dates, giving me a date_duration to work with:
boost::gregorian::date rhs(2000, 1, 1);
boost::gregorian::date lhs(2005, 6, 15);
boost::gregorian::date_duration dd = lhs - rhs;
boost::gregorian::days daysOld(dd);
boost::gregorian::months monthsOld(...) // This is where I'm stumped
boost::gregorian::years yearsOld(...)
The boost::gregorian::days ctor can take a date_duration, but I can't find a way to create a similar representation from the date_duration for months and years. It seems, from what I have read and seen, that date_duration only contains the number of days in the interval between the two dates. What I was hoping for was that it would give me non-normalized members for years, months, and days. For example, with the above dates, I would expect date_duration to have fields that gave something like years = 5
, months = 65
, and days = 1992
where each field represents the total amount of time using that particular time granularity. As it stands, there appears to only be a way to access the date_duration as a number of days between the dates (by calling dd.days()
). Am I missing something? Is there any way to accomplish this using boost::gregorian or one of the other date/time libraries?
Thanks