bool UnitMgr::doConversion(double fromValue, double fromScale, UnitDefPtr fromUnitDef, double& toValue, double toScale, UnitDefPtr toUnitDef, const Date_Time& when, bool whenIsValid) const { // The key to understanding this method: the conversion factor // associated with a unit is for converting from that unit to the // standard unit for that type. When the unit is "per month", this // conversion factor assumes a 31 day month, and when the unit is // "per year", this conversion factor assumes a 365 day year. int daysIn (0); // days in month or year // Debug Support if (whenIsValid && (when.get_year() == 2016)) { static int diagCnt (0); ++diagCnt; // debug breakpoint } // Get the factor for converting to standard units and correct it // for the actual length of the month or year. double coeffToStd( fromUnitDef->getFactor() ); if (fromUnitDef->isPerMonth() && whenIsValid && (daysIn = when.daysInMonth()) != 31) { coeffToStd *= double(daysIn) / double(31); } else if (fromUnitDef->isPerYear() && whenIsValid && (daysIn = when.daysInYear()) != 365) { coeffToStd *= double(daysIn) / double(365); } // Convert the given value to an intermediate value in standard units. double stdValue( ( fromValue / coeffToStd ) * fromScale ); // Get the factor for converting from standard units and correct it // for the actual length of the month or year. double coeffFromStd( toUnitDef->getFactor() ); if (toUnitDef->isPerMonth() && whenIsValid && (daysIn = when.daysInMonth()) != 31) { coeffFromStd *= double(daysIn) / double(31); } else if (toUnitDef->isPerYear() && whenIsValid && (daysIn = when.daysInYear()) != 365) { coeffFromStd *= double(daysIn) / double(365); } // Convert the intermediate value to the desired units and scale. toValue = stdValue * coeffFromStd / toScale; return false; // success } ---