Sort exports by date, newest to oldest.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
tastytea 2019-07-26 03:11:44 +02:00
parent 1d802d5b67
commit aa16dad796
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
3 changed files with 19 additions and 3 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.2) cmake_minimum_required (VERSION 3.2)
project(remwharead project(remwharead
VERSION 0.6.2 VERSION 0.6.3
LANGUAGES CXX LANGUAGES CXX
) )

View File

@ -14,12 +14,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <algorithm>
#include "export.hpp" #include "export.hpp"
namespace Export namespace Export
{ {
ExportBase::ExportBase(const vector<Database::entry> &entries, ostream &out) ExportBase::ExportBase(const vector<Database::entry> &entries, ostream &out)
: _entries(entries) : _entries(sort_entries(entries))
, _out(out) , _out(out)
{} {}
const vector<Database::entry>
ExportBase::sort_entries(vector<Database::entry> entries) const
{
std::sort(entries.begin(), entries.end(),
[](const auto &a, const auto &b)
{
return (a.datetime > b.datetime);
});
return entries;
}
} }

View File

@ -36,8 +36,12 @@ namespace Export
virtual void print() const = 0; virtual void print() const = 0;
protected: protected:
const vector<Database::entry> &_entries; const vector<Database::entry> _entries;
ostream &_out; ostream &_out;
//! Sort entries from newest to oldest.
const vector<Database::entry>
sort_entries(vector<Database::entry> entries) const;
}; };
} }