mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
validate: Renamed validateInterval to vaildate, and integrated
This commit is contained in:
parent
123655079c
commit
f66127f473
17 changed files with 135 additions and 48 deletions
|
@ -17,7 +17,8 @@ set (timew_SRCS CLI.cpp CLI.h
|
|||
init.cpp
|
||||
helper.cpp
|
||||
log.cpp
|
||||
util.cpp)
|
||||
util.cpp
|
||||
validate.cpp)
|
||||
|
||||
set (libshared_SRCS libshared/src/Args.cpp libshared/src/Args.h
|
||||
libshared/src/Color.cpp libshared/src/Color.h
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CmdContinue (
|
||||
const CLI& cli,
|
||||
Rules& rules,
|
||||
Database& database)
|
||||
{
|
||||
|
@ -41,7 +42,7 @@ int CmdContinue (
|
|||
{
|
||||
// Open an identical interval and update hte DB.
|
||||
latest.range.open ();
|
||||
validateInterval (database, rules, latest);
|
||||
validate (cli, rules, database, latest);
|
||||
database.addInterval (latest);
|
||||
|
||||
if (rules.getBoolean ("verbose"))
|
||||
|
|
|
@ -76,7 +76,7 @@ int CmdJoin (
|
|||
combined.range.end = second.range.end;
|
||||
|
||||
database.deleteInterval (second);
|
||||
validateInterval (database, rules, combined);
|
||||
validate (cli, rules, database, combined);
|
||||
database.modifyInterval (first, combined);
|
||||
|
||||
// Feedback.
|
||||
|
|
|
@ -69,7 +69,7 @@ int CmdLengthen (
|
|||
Duration dur (delta);
|
||||
i.range.end += dur.toTime_t ();
|
||||
|
||||
validateInterval (database, rules, i);
|
||||
validate (cli, rules, database, i);
|
||||
database.modifyInterval (tracked[tracked.size () - id], i);
|
||||
|
||||
// Feedback.
|
||||
|
|
|
@ -86,7 +86,7 @@ int CmdMove (
|
|||
i.range.end -= delta;
|
||||
}
|
||||
|
||||
validateInterval (database, rules, i);
|
||||
validate (cli, rules, database, i);
|
||||
database.modifyInterval (tracked[tracked.size () - id], i);
|
||||
|
||||
// Feedback.
|
||||
|
|
|
@ -71,7 +71,7 @@ int CmdShorten (
|
|||
{
|
||||
i.range.end -= dur.toTime_t ();
|
||||
|
||||
validateInterval (database, rules, i);
|
||||
validate (cli, rules, database, i);
|
||||
database.modifyInterval (tracked[tracked.size () - id], i);
|
||||
|
||||
// Feedback.
|
||||
|
|
|
@ -81,9 +81,9 @@ int CmdSplit (
|
|||
second.range.start = midpoint;
|
||||
}
|
||||
|
||||
validateInterval (database, rules, first);
|
||||
validate (cli, rules, database, first);
|
||||
database.modifyInterval (tracked[tracked.size () - id], first);
|
||||
validateInterval (database, rules, second);
|
||||
validate (cli, rules, database, second);
|
||||
database.addInterval (second);
|
||||
|
||||
// Feedback.
|
||||
|
|
|
@ -73,7 +73,7 @@ int CmdStart (
|
|||
now.tag (tag);
|
||||
|
||||
// Update database. An open interval does not need to be flattened.
|
||||
validateInterval (database, rules, now);
|
||||
validate (cli, rules, database, now);
|
||||
database.addInterval (now);
|
||||
|
||||
// TODO intervalSummarїze needs to operate on a vector of similar intervals.
|
||||
|
|
|
@ -66,7 +66,7 @@ int CmdStop (
|
|||
modified.range.end = Datetime ();
|
||||
|
||||
// Close the interval.
|
||||
validateInterval (database, rules, modified);
|
||||
validate (cli, rules, database, modified);
|
||||
database.modifyInterval (latest, modified);
|
||||
|
||||
// If tags are specified, but are not a full set of tags, remove them
|
||||
|
@ -91,7 +91,7 @@ int CmdStop (
|
|||
{
|
||||
modified.range.start = modified.range.end;
|
||||
modified.range.end = {0};
|
||||
validateInterval (database, rules, modified);
|
||||
validate (cli, rules, database, modified);
|
||||
database.addInterval (modified);
|
||||
if (rules.getBoolean ("verbose"))
|
||||
std::cout << '\n' << intervalSummarize (database, rules, modified);
|
||||
|
|
|
@ -64,7 +64,7 @@ int CmdTag (
|
|||
for (auto& tag : tags)
|
||||
i.tag (tag);
|
||||
|
||||
validateInterval (database, rules, i);
|
||||
validate (cli, rules, database, i);
|
||||
database.modifyInterval (tracked[tracked.size () - id], i);
|
||||
|
||||
// Feedback.
|
||||
|
|
|
@ -45,7 +45,7 @@ int CmdTrack (
|
|||
auto exclusions = getAllExclusions (rules, filter.range);
|
||||
for (auto& interval : flatten (filter, exclusions))
|
||||
{
|
||||
validateInterval (database, rules, interval);
|
||||
validate (cli, rules, database, interval);
|
||||
database.addInterval (interval);
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ int CmdUntag (
|
|||
for (auto& tag : tags)
|
||||
i.untag (tag);
|
||||
|
||||
validateInterval (database, rules, i);
|
||||
validate (cli, rules, database, i);
|
||||
database.modifyInterval (tracked[tracked.size () - id], i);
|
||||
|
||||
// Feedback.
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
int CmdCancel ( Rules&, Database& );
|
||||
int CmdClear (const CLI&, Rules&, Database& );
|
||||
int CmdConfig (const CLI&, Rules&, Database& );
|
||||
int CmdContinue ( Rules&, Database& );
|
||||
int CmdContinue (const CLI&, Rules&, Database& );
|
||||
int CmdDefault ( Rules&, Database& );
|
||||
int CmdDiagnostics ( Rules&, Database&, const Extensions&);
|
||||
int CmdExport (const CLI&, Rules&, Database& );
|
||||
|
|
|
@ -411,34 +411,3 @@ std::string minimalDelta (const Datetime& left, const Datetime& right)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void validateInterval (
|
||||
Database& database,
|
||||
const Rules& rules,
|
||||
const Interval& interval)
|
||||
{
|
||||
// TODO Need to verify that interval.tags do not overlap with stored data.
|
||||
// Unless the tags that overlap are allowed to overlap.
|
||||
|
||||
// Warn on new tag.
|
||||
if (rules.getBoolean ("verbose"))
|
||||
{
|
||||
std::set <std::string> tags;
|
||||
for (auto& line : database.allLines ())
|
||||
{
|
||||
if (line[0] == 'i')
|
||||
{
|
||||
Interval interval;
|
||||
interval.initialize (line);
|
||||
|
||||
for (auto& tag : interval.tags ())
|
||||
tags.insert (tag);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& tag : interval.tags ())
|
||||
if (tags.find (tag) == tags.end ())
|
||||
std::cout << "Note: '" << tag << "' is a new tag.\n";
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -258,7 +258,7 @@ int dispatchCommand (
|
|||
if (command == "cancel") status = CmdCancel ( rules, database );
|
||||
else if (command == "clear") status = CmdClear (cli, rules, database );
|
||||
else if (command == "config") status = CmdConfig (cli, rules, database );
|
||||
else if (command == "continue") status = CmdContinue ( rules, database );
|
||||
else if (command == "continue") status = CmdContinue (cli, rules, database );
|
||||
else if (command == "day") status = CmdChartDay (cli, rules, database );
|
||||
else if (command == "diagnostics") status = CmdDiagnostics ( rules, database, extensions);
|
||||
else if (command == "export") status = CmdExport (cli, rules, database );
|
||||
|
|
|
@ -56,6 +56,9 @@ std::vector <Range> getUntracked (Database&, const Rules&, Interval&);
|
|||
Interval getLatestInterval (Database&);
|
||||
Range getFullDay (const Datetime&);
|
||||
|
||||
// validate.cpp
|
||||
void validate (const CLI& cli, const Rules& rules, Database&, Interval&);
|
||||
|
||||
// init.cpp
|
||||
bool lightweightVersionCheck (int, const char**);
|
||||
void initializeEntities (CLI&);
|
||||
|
@ -75,7 +78,6 @@ int quantizeToNMinutes (const int, const int);
|
|||
bool dayIsHoliday (const Rules&, const Datetime&);
|
||||
bool findHint (const CLI&, const std::string&);
|
||||
std::string minimalDelta (const Datetime&, const Datetime&);
|
||||
void validateInterval (Database&, const Rules&, const Interval&);
|
||||
|
||||
// log.cpp
|
||||
void enableDebugMode (bool);
|
||||
|
|
114
src/validate.cpp
Normal file
114
src/validate.cpp
Normal file
|
@ -0,0 +1,114 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 <timew.h>
|
||||
#include <iostream>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// :fill
|
||||
// The :fill hint is used to eliminate gaps on interval modification, and only
|
||||
// a single interval is affected.
|
||||
//
|
||||
// Fill works by extending an interval in both directions if possible, to abut
|
||||
// either an interval or an exclusion, while being conћtrained by a filter
|
||||
// range.
|
||||
//
|
||||
static void autoFill (
|
||||
const Rules& rules,
|
||||
Database& database,
|
||||
const Interval& filter,
|
||||
Interval& interval)
|
||||
{
|
||||
// TODO Get all intervals.
|
||||
// TODO Get all exclusions.
|
||||
// TODO Determine all gaps.
|
||||
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// :adjust
|
||||
// To avoid disallowed overlaps, one or more intervals may be modified to
|
||||
// resolve the conflict according to configuration-based rules. Resolution
|
||||
// can involve rejection, adjustment of modified interval, or adjustment of
|
||||
// recorded data.
|
||||
//
|
||||
static void autoAdjust (
|
||||
const Rules& rules,
|
||||
Database& database,
|
||||
const Interval& filter,
|
||||
Interval& interval)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Warn on new tag.
|
||||
static void warnOnNewTag (
|
||||
Database& database,
|
||||
const Interval& interval)
|
||||
{
|
||||
std::set <std::string> tags;
|
||||
for (auto& line : database.allLines ())
|
||||
{
|
||||
if (line[0] == 'i')
|
||||
{
|
||||
Interval interval;
|
||||
interval.initialize (line);
|
||||
|
||||
for (auto& tag : interval.tags ())
|
||||
tags.insert (tag);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& tag : interval.tags ())
|
||||
if (tags.find (tag) == tags.end ())
|
||||
std::cout << "Note: '" << tag << "' is a new tag.\n";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void validate (
|
||||
const CLI& cli,
|
||||
const Rules& rules,
|
||||
Database& database,
|
||||
Interval& interval)
|
||||
{
|
||||
// Create a filter, and if empty, choose 'today'.
|
||||
auto filter = getFilter (cli);
|
||||
if (! filter.range.is_started ())
|
||||
filter.range = Range (Datetime ("today"), Datetime ("tomorrow"));
|
||||
|
||||
if (findHint (cli, ":fill"))
|
||||
autoFill (rules, database, filter, interval);
|
||||
|
||||
if (findHint (cli, ":adjust"))
|
||||
autoAdjust (rules, database, filter, interval);
|
||||
|
||||
if (rules.getBoolean ("verbose"))
|
||||
warnOnNewTag (database, interval);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
Loading…
Add table
Add a link
Reference in a new issue