Database: Datafiles now initialized on demand

This commit is contained in:
Paul Beckingham 2016-04-17 10:59:00 -04:00
parent 67949c3a43
commit ebb3d63da5
2 changed files with 23 additions and 0 deletions

View file

@ -243,3 +243,25 @@ std::vector <Daterange> Database::segmentRange (const Daterange& range)
}
////////////////////////////////////////////////////////////////////////////////
void Database::initializeDatafiles ()
{
// Because the data files have names YYYY-MM.data, sorting them by name also
// sorts by the intervals within.
Directory d (_location);
auto files = d.list ();
std::sort (files.begin (), files.end ());
for (auto& file : files)
{
// If it looks like a data file.
if (file.find (".data") == file.length () - 5)
{
auto basename = File (file).name ();
auto year = strtol (basename.substr (0, 4).c_str (), NULL, 10);
auto month = strtol (basename.substr (5, 2).c_str (), NULL, 10);
getDatafile (year, month);
}
}
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -55,6 +55,7 @@ public:
private:
unsigned int getDatafile (int, int);
std::vector <Daterange> segmentRange (const Daterange&);
void initializeDatafiles ();
private:
std::string _location {"~/.timewarrior/data"};