CmdCancel: Added new command to abandon an active interval

This commit is contained in:
Paul Beckingham 2016-04-29 21:37:32 -04:00
parent abe6ccfd89
commit 1522af15e6
3 changed files with 59 additions and 1 deletions

View file

@ -5,7 +5,8 @@ include_directories (${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src/libshared/src ${CMAKE_SOURCE_DIR}/src/libshared/src
${TIMEW_INCLUDE_DIRS}) ${TIMEW_INCLUDE_DIRS})
set (commands_SRCS CmdClear.cpp set (commands_SRCS CmdCancel.cpp
CmdClear.cpp
CmdConfig.cpp CmdConfig.cpp
CmdContinue.cpp CmdContinue.cpp
CmdDefault.cpp CmdDefault.cpp

View file

@ -0,0 +1,56 @@
////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2015 - 2016, Paul Beckingham, Federico Hernandez.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// http://www.opensource.org/licenses/mit-license.php
//
////////////////////////////////////////////////////////////////////////////////
#include <cmake.h>
#include <commands.h>
#include <timew.h>
#include <Interval.h>
#include <iostream>
////////////////////////////////////////////////////////////////////////////////
int CmdCancel (
Rules& rules,
Database& database)
{
// If there is an open interval, cancel it.
auto latest = getLatestInterval (database);
if ( latest.range.started () &&
! latest.range.ended ())
{
database.deleteInterval (latest);
if (rules.getBoolean ("verbose"))
std::cout << "Canceled active time tracking.\n";
}
else
{
if (rules.getBoolean ("verbose"))
std::cout << "There is no active time tracking.\n";
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -32,6 +32,7 @@
#include <Database.h> #include <Database.h>
#include <Extensions.h> #include <Extensions.h>
int CmdCancel ( Rules&, Database& );
int CmdClear ( ); int CmdClear ( );
int CmdConfig ( ); int CmdConfig ( );
int CmdContinue ( Rules&, Database& ); int CmdContinue ( Rules&, Database& );