Changeset View
Changeset View
Standalone View
Standalone View
src/recurrencerule.cpp
Show First 20 Lines • Show All 1502 Lines • ▼ Show 20 Line(s) | 1502 | if (!match) { | |||
---|---|---|---|---|---|
1503 | return false; | 1503 | return false; | ||
1504 | } | 1504 | } | ||
1505 | 1505 | | |||
1506 | // We really need to obtain the list of dates in this interval, since | 1506 | // We really need to obtain the list of dates in this interval, since | ||
1507 | // otherwise BYSETPOS will not work (i.e. the date will match the interval, | 1507 | // otherwise BYSETPOS will not work (i.e. the date will match the interval, | ||
1508 | // but BYSETPOS selects only one of these matching dates! | 1508 | // but BYSETPOS selects only one of these matching dates! | ||
1509 | do { | 1509 | do { | ||
1510 | auto dts = d->datesForInterval(interval, recurrenceType()); | 1510 | auto dts = d->datesForInterval(interval, recurrenceType()); | ||
1511 | int i = dts.findGE(start); | 1511 | const auto it = std::lower_bound(dts.constBegin(), dts.constEnd(), start); | ||
1512 | if (i >= 0) { | 1512 | if (it != dts.constEnd()) { | ||
1513 | return dts[i] <= end; | 1513 | return *it <= end; | ||
1514 | } | 1514 | } | ||
1515 | interval.increase(recurrenceType(), frequency()); | 1515 | interval.increase(recurrenceType(), frequency()); | ||
1516 | } while (interval.intervalDateTime(recurrenceType()).isValid() && | 1516 | } while (interval.intervalDateTime(recurrenceType()).isValid() && | ||
1517 | interval.intervalDateTime(recurrenceType()) < end); | 1517 | interval.intervalDateTime(recurrenceType()) < end); | ||
1518 | 1518 | | |||
1519 | return false; | 1519 | return false; | ||
1520 | } | 1520 | } | ||
1521 | 1521 | | |||
▲ Show 20 Lines • Show All 162 Lines • ▼ Show 20 Line(s) | 1681 | if (d->mTimedRepetition) { | |||
1684 | QDateTime next = fromDate.addSecs(d->mTimedRepetition - n + 1); | 1684 | QDateTime next = fromDate.addSecs(d->mTimedRepetition - n + 1); | ||
1685 | return d->mDuration < 0 || !endDt().isValid() || next <= endDt() ? next : QDateTime(); | 1685 | return d->mDuration < 0 || !endDt().isValid() || next <= endDt() ? next : QDateTime(); | ||
1686 | } | 1686 | } | ||
1687 | 1687 | | |||
1688 | if (d->mDuration > 0) { | 1688 | if (d->mDuration > 0) { | ||
1689 | if (!d->mCached) { | 1689 | if (!d->mCached) { | ||
1690 | d->buildCache(); | 1690 | d->buildCache(); | ||
1691 | } | 1691 | } | ||
1692 | int i = d->mCachedDates.findGT(fromDate); | 1692 | const auto it = std::upper_bound(d->mCachedDates.constBegin(), d->mCachedDates.constEnd(), fromDate); | ||
1693 | if (i >= 0) { | 1693 | if (it != d->mCachedDates.constEnd()) { | ||
1694 | return d->mCachedDates[i]; | 1694 | return *it; | ||
1695 | } | 1695 | } | ||
1696 | } | 1696 | } | ||
1697 | 1697 | | |||
1698 | QDateTime end = endDt(); | 1698 | QDateTime end = endDt(); | ||
1699 | Constraint interval(d->getNextValidDateInterval(fromDate, recurrenceType())); | 1699 | Constraint interval(d->getNextValidDateInterval(fromDate, recurrenceType())); | ||
1700 | auto dts = d->datesForInterval(interval, recurrenceType()); | 1700 | const auto dts = d->datesForInterval(interval, recurrenceType()); | ||
1701 | int i = dts.findGT(fromDate); | 1701 | const auto it = std::upper_bound(dts.begin(), dts.end(), fromDate); | ||
1702 | if (i >= 0) { | 1702 | if (it != dts.end()) { | ||
1703 | return (d->mDuration < 0 || dts[i] <= end) ? dts[i] : QDateTime(); | 1703 | return (d->mDuration < 0 || *it <= end) ? *it : QDateTime(); | ||
1704 | } | 1704 | } | ||
1705 | interval.increase(recurrenceType(), frequency()); | 1705 | interval.increase(recurrenceType(), frequency()); | ||
1706 | if (d->mDuration >= 0 && interval.intervalDateTime(recurrenceType()) > end) { | 1706 | if (d->mDuration >= 0 && interval.intervalDateTime(recurrenceType()) > end) { | ||
1707 | return QDateTime(); | 1707 | return QDateTime(); | ||
1708 | } | 1708 | } | ||
1709 | 1709 | | |||
1710 | // Increase the interval. The first occurrence that we find is the result (if | 1710 | // Increase the interval. The first occurrence that we find is the result (if | ||
1711 | // if's before the end date). | 1711 | // if's before the end date). | ||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | 1732 | { | |||
1779 | bool done = false; | 1779 | bool done = false; | ||
1780 | if (d->mDuration > 0) { | 1780 | if (d->mDuration > 0) { | ||
1781 | if (!d->mCached) { | 1781 | if (!d->mCached) { | ||
1782 | d->buildCache(); | 1782 | d->buildCache(); | ||
1783 | } | 1783 | } | ||
1784 | if (d->mCachedDateEnd.isValid() && start > d->mCachedDateEnd) { | 1784 | if (d->mCachedDateEnd.isValid() && start > d->mCachedDateEnd) { | ||
1785 | return result; // beyond end of recurrence | 1785 | return result; // beyond end of recurrence | ||
1786 | } | 1786 | } | ||
1787 | int i = d->mCachedDates.findGE(start); | 1787 | const auto it = std::lower_bound(d->mCachedDates.constBegin(), d->mCachedDates.constEnd(), start); | ||
1788 | if (i >= 0) { | 1788 | if (it != d->mCachedDates.constEnd()) { | ||
1789 | int iend = d->mCachedDates.findGT(enddt, i); | 1789 | const auto itEnd = std::upper_bound(it, d->mCachedDates.constEnd(), enddt); | ||
1790 | if (iend < 0) { | 1790 | if (itEnd != d->mCachedDates.constEnd()) { | ||
1791 | iend = d->mCachedDates.count(); | | |||
1792 | } else { | | |||
1793 | done = true; | 1791 | done = true; | ||
1794 | } | 1792 | } | ||
1795 | while (i < iend) { | 1793 | std::copy(it, itEnd, std::back_inserter(result)); | ||
1796 | result += d->mCachedDates[i++]; | | |||
1797 | } | | |||
1798 | } | 1794 | } | ||
1799 | if (d->mCachedDateEnd.isValid()) { | 1795 | if (d->mCachedDateEnd.isValid()) { | ||
1800 | done = true; | 1796 | done = true; | ||
1801 | } else if (!result.isEmpty()) { | 1797 | } else if (!result.isEmpty()) { | ||
1802 | result += QDateTime(); // indicate that the returned list is incomplete | 1798 | result += QDateTime(); // indicate that the returned list is incomplete | ||
1803 | done = true; | 1799 | done = true; | ||
1804 | } | 1800 | } | ||
1805 | if (done) { | 1801 | if (done) { | ||
1806 | return result; | 1802 | return result; | ||
1807 | } | 1803 | } | ||
1808 | // We don't have any result yet, but we reached the end of the incomplete cache | 1804 | // We don't have any result yet, but we reached the end of the incomplete cache | ||
1809 | st = d->mCachedLastDate.addSecs(1); | 1805 | st = d->mCachedLastDate.addSecs(1); | ||
1810 | } | 1806 | } | ||
1811 | 1807 | | |||
1812 | Constraint interval(d->getNextValidDateInterval(st, recurrenceType())); | 1808 | Constraint interval(d->getNextValidDateInterval(st, recurrenceType())); | ||
1813 | int loop = 0; | 1809 | int loop = 0; | ||
1814 | do { | 1810 | do { | ||
1815 | auto dts = d->datesForInterval(interval, recurrenceType()); | 1811 | auto dts = d->datesForInterval(interval, recurrenceType()); | ||
1816 | int i = 0; | 1812 | auto it = dts.begin(); | ||
1817 | int iend = dts.count(); | 1813 | auto itEnd = dts.end(); | ||
1818 | if (loop == 0) { | 1814 | if (loop == 0) { | ||
1819 | i = dts.findGE(st); | 1815 | it = std::lower_bound(dts.begin(), dts.end(), st); | ||
1820 | if (i < 0) { | | |||
1821 | i = iend; | | |||
1822 | } | 1816 | } | ||
1823 | } | 1817 | itEnd = std::upper_bound(it, dts.end(), enddt); | ||
1824 | int j = dts.findGT(enddt, i); | 1818 | if (itEnd != dts.end()) { | ||
1825 | if (j >= 0) { | | |||
1826 | iend = j; | | |||
1827 | loop = LOOP_LIMIT; | 1819 | loop = LOOP_LIMIT; | ||
1828 | } | 1820 | } | ||
1829 | while (i < iend) { | 1821 | std::copy(it, itEnd, std::back_inserter(result)); | ||
1830 | result += dts[i++]; | | |||
1831 | } | | |||
1832 | // Increase the interval. | 1822 | // Increase the interval. | ||
1833 | interval.increase(recurrenceType(), frequency()); | 1823 | interval.increase(recurrenceType(), frequency()); | ||
1834 | } while (++loop < LOOP_LIMIT && | 1824 | } while (++loop < LOOP_LIMIT && | ||
1835 | interval.intervalDateTime(recurrenceType()) < end); | 1825 | interval.intervalDateTime(recurrenceType()) < end); | ||
1836 | return result; | 1826 | return result; | ||
1837 | } | 1827 | } | ||
1838 | 1828 | | |||
1839 | //@cond PRIVATE | 1829 | //@cond PRIVATE | ||
▲ Show 20 Lines • Show All 487 Lines • Show Last 20 Lines |