mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Database: Identified current data file name
This commit is contained in:
parent
39a3a4aed6
commit
a3c468e8a6
2 changed files with 31 additions and 1 deletions
|
@ -29,21 +29,29 @@
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iostream> // TODO Remove
|
#include <iostream> // TODO Remove
|
||||||
|
#include <iomanip>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void Database::initialize (const std::string& location)
|
void Database::initialize (const std::string& location)
|
||||||
{
|
{
|
||||||
_location = location;
|
_location = location;
|
||||||
|
_current = currentDataFile ();
|
||||||
|
_data_files.push_back (_current);
|
||||||
|
|
||||||
Directory d (_location);
|
Directory d (_location);
|
||||||
for (const auto& file : d.list ())
|
for (const auto& file : d.list ())
|
||||||
{
|
{
|
||||||
if (1 /* looks like one of our data files */)
|
if (1 /* looks like one of our data files */)
|
||||||
{
|
{
|
||||||
_data_files.push_back (file);
|
if (file != _current)
|
||||||
|
_data_files.push_back (file);
|
||||||
|
|
||||||
std::cout << "# data file " << file << "\n";
|
std::cout << "# data file " << file << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO If there is no data file named YYYY—MM.data, then create it.
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -58,3 +66,21 @@ std::string Database::dump () const
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
std::string Database::currentDataFile () const
|
||||||
|
{
|
||||||
|
time_t current;
|
||||||
|
time (¤t);
|
||||||
|
struct tm* t = gmtime (¤t);
|
||||||
|
|
||||||
|
std::stringstream out;
|
||||||
|
out << _location
|
||||||
|
<< '/'
|
||||||
|
<< std::setw (4) << std::setfill ('0') << (t->tm_year + 1900)
|
||||||
|
<< '-'
|
||||||
|
<< std::setw (2) << std::setfill ('0') << (t->tm_mon + 1)
|
||||||
|
<< ".data";
|
||||||
|
|
||||||
|
return out.str ();
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -37,8 +37,12 @@ public:
|
||||||
void initialize (const std::string&);
|
void initialize (const std::string&);
|
||||||
std::string dump () const;
|
std::string dump () const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string currentDataFile () const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string _location {"~/.timewarrior/data"};
|
std::string _location {"~/.timewarrior/data"};
|
||||||
|
std::string _current {};
|
||||||
std::vector <std::string> _data_files {};
|
std::vector <std::string> _data_files {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue