mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-06-26 10:54:28 +02:00
Datafile: Extracts YYYY and MM from it's file
This commit is contained in:
parent
a199c2e161
commit
d0da2c9ac6
2 changed files with 17 additions and 2 deletions
|
@ -26,12 +26,23 @@
|
||||||
|
|
||||||
#include <cmake.h>
|
#include <cmake.h>
|
||||||
#include <Datafile.h>
|
#include <Datafile.h>
|
||||||
|
#include <FS.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void Datafile::initialize (const std::string& name)
|
void Datafile::initialize (const std::string& name)
|
||||||
{
|
{
|
||||||
_name = name;
|
_name = name;
|
||||||
|
|
||||||
|
// From the name, which is of the form YYYY-MM.data, extract the YYYY and MM.
|
||||||
|
auto basename = File (_name).name ();
|
||||||
|
auto year = strtol (basename.substr (0, 4).c_str (), NULL, 10);
|
||||||
|
auto month = strtol (basename.substr (5, 2).c_str (), NULL, 10);
|
||||||
|
|
||||||
|
// Construct two dates that
|
||||||
|
_day1 = Datetime (month, 1, year, 0 , 0, 0);
|
||||||
|
_dayN = Datetime (month, Datetime::daysInMonth (year, month), year, 23, 59, 59);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -79,8 +90,10 @@ void Datafile::commit ()
|
||||||
std::string Datafile::dump () const
|
std::string Datafile::dump () const
|
||||||
{
|
{
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
out << "Datafile\n";
|
out << "Datafile\n"
|
||||||
out << " Name: " << _name << "\n";
|
<< " Name: " << _name << "\n"
|
||||||
|
<< " day1: " << _day1.toISO () << "\n"
|
||||||
|
<< " dayN: " << _dayN.toISO () << "\n";
|
||||||
|
|
||||||
return out.str ();
|
return out.str ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,8 @@ public:
|
||||||
private:
|
private:
|
||||||
std::string _name {};
|
std::string _name {};
|
||||||
bool _dirty {false};
|
bool _dirty {false};
|
||||||
|
Datetime _day1 {0};
|
||||||
|
Datetime _dayN {0};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue