mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Database: Datafiles now initialized on demand
This commit is contained in:
parent
67949c3a43
commit
ebb3d63da5
2 changed files with 23 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -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"};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue