Currency RoutineAllocator::allocate(DateRange const& period, Currency available)
{
   DateRange range;
   if (m_history.isEmpty())
   {
      range = DateRange();
   }
   else
   {
      Q_ASSERT(m_history.lastKey() < period.startDate());
      range = DateRange(m_history.firstKey(), period.startDate().addDays(-1));
   }
   DateRange firstDay(range.startDate(), range.startDate());

   foreach (Currency const& total, m_historyTotals)
   {
      Currency amount = total.amortize(range, firstDay) * period.days();
      m_allocation -= amount;
      available += amount;
   }
Beispiel #2
0
DateRange DateRange::intersect(DateRange const& other) const
{
   if (isNull() || other.isNull())
   {
      return DateRange();
   }

   QDate startDate = std::max(m_startDate, other.startDate());
   QDate endDate = std::min(this->endDate(), other.endDate());
   if (startDate <= endDate)
   {
      return DateRange(startDate, endDate);
   }
   else
   {
      return DateRange();
   }
}