CmdStop: Implemented 'stop'

This commit is contained in:
Paul Beckingham 2016-03-20 15:31:09 -04:00
parent a95ee17a3c
commit f554734150

View file

@ -26,6 +26,7 @@
#include <cmake.h> #include <cmake.h>
#include <commands.h> #include <commands.h>
#include <Interval.h>
#include <iostream> #include <iostream>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -33,11 +34,29 @@ int CmdStop (
Database& database, Database& database,
Log& log) Log& log)
{ {
std::cout << "[stop: end an open tracking interval]\n"; // Load the most recent interval.
auto latest = database.getLatestInterval ();
// TODO Load the most recent interval. // Verify the interval is open.
// TODO Verify the interval is open. if ( latest.isStarted () &&
// TODO Close the interval. ! latest.isEnded ())
{
// Stop it.
latest.end (Datetime ());
// Update database.
database.modifyInterval (latest);
log.write ("debug", std::string ("Stopped tracking: ") + latest.serialize ());
// TODO User feedback.
// TODO Summarize closed interval.
}
else
{
std::string message = "There is no time currently being tracked.";
std::cout << "Warning: " << message << "\n";
log.write ("warning", message);
}
return 0; return 0;
} }