37 #include <api/OperationType.hpp> 38 #include <api/TimePeriod.hpp> 39 #include <async/Future.hpp> 40 #include <utils/DateUtils.hpp> 41 #include <utils/Option.hpp> 60 template <
typename Op,
typename Value,
typename CastValue,
typename OperationIt>
61 std::vector<std::shared_ptr<CastValue>> getBalanceHistoryFor(
62 std::chrono::system_clock::time_point
const& startDate,
63 std::chrono::system_clock::time_point
const& endDate,
64 api::TimePeriod precision,
65 OperationIt operationIt,
66 OperationIt operationEnd,
69 if (startDate >= endDate) {
71 "Start date should be strictly greater than end date");
74 auto lowerDate = startDate;
75 auto upperDate = DateUtils::incrementDate(startDate, precision);
76 std::vector<std::shared_ptr<CastValue>> values;
79 while (lowerDate <= endDate && operationIt != operationEnd) {
80 auto operation = *operationIt;
81 auto operationDate = Op::date(operation);
83 while (operationDate > upperDate && lowerDate < endDate) {
84 lowerDate = DateUtils::incrementDate(lowerDate, precision);
85 upperDate = DateUtils::incrementDate(upperDate, precision);
86 values.emplace_back(Op::value_constructor(sum));
89 if (operationDate <= upperDate) {
90 Op::update_balance(operation, sum);
96 while (lowerDate < endDate) {
97 lowerDate = DateUtils::incrementDate(lowerDate, precision);
98 values.emplace_back(Op::value_constructor(sum));
Definition: Account.cpp:8