Skip to content

Commit

Permalink
Allow for closed intervals with start date in the future
Browse files Browse the repository at this point in the history
- open intervals still have to start before now (move check to CmdStart)
- Closes #62
- Closes #142
  • Loading branch information
lauft committed Oct 19, 2018
1 parent 81bfbf4 commit 72cfe7b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 30 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ Thanks to the following, who submitted detailed bug reports and excellent sugges
lumbric lumbric
Antanas B. Antanas B.
towo towo
sclo
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- #9 Add an 'undo' command (TI-1) - #9 Add an 'undo' command (TI-1)
- #21 Add/Remove tag to/from current activity (TI-13) - #21 Add/Remove tag to/from current activity (TI-13)
(thanks to lumbric) (thanks to lumbric)
- #62 `timew track` with future interval records nothing or incomplete interval (TI-57)
- #68 Add annotations to time intervals (TI-63) - #68 Add annotations to time intervals (TI-63)
- #77 Support non-tag interval data storage (TI-72) - #77 Support non-tag interval data storage (TI-72)
(thanks to Tomas Babej) (thanks to Tomas Babej)
Expand All @@ -22,6 +23,8 @@
(thanks to towo) (thanks to towo)
- #138 Entering an escaped quote in a tag name causes incorrect JSON to be generated - #138 Entering an escaped quote in a tag name causes incorrect JSON to be generated
(thanks to bognolo) (thanks to bognolo)
- #142 allow setting end of task in future
(thanks to sclo)
- #157 CLI: Ensure IDs are non-zero - #157 CLI: Ensure IDs are non-zero
(thanks to janikrabe) (thanks to janikrabe)
- #165 CmdSummary does not show empty intervals at midnight - #165 CmdSummary does not show empty intervals at midnight
Expand Down
22 changes: 14 additions & 8 deletions src/commands/CmdStart.cpp
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
// Copyright 2015 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez. // Copyright 2016 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -36,6 +36,12 @@ int CmdStart (
{ {
// Add a new open interval, which may have a defined start time. // Add a new open interval, which may have a defined start time.
auto filter = getFilter (cli); auto filter = getFilter (cli);

auto now = Datetime ();

if (filter.start > now)
throw std::string ("Time tracking cannot be set in the future.");

auto latest = getLatestInterval (database); auto latest = getLatestInterval (database);


database.startTransaction (); database.startTransaction ();
Expand Down Expand Up @@ -74,21 +80,21 @@ int CmdStart (
} }


// Now add the new open interval. // Now add the new open interval.
Interval now; Interval started;
if (filter.start.toEpoch () != 0) if (filter.start.toEpoch () != 0)
now.start = filter.start; started.start = filter.start;
else else
now.start = Datetime (); started.start = Datetime ();


for (auto& tag : filter.tags ()) for (auto& tag : filter.tags ())
now.tag (tag); started.tag (tag);


// Update database. An open interval does not need to be flattened. // Update database. An open interval does not need to be flattened.
validate (cli, rules, database, now); validate (cli, rules, database, started);
database.addInterval (now, rules.getBoolean ("verbose")); database.addInterval (started, rules.getBoolean ("verbose"));


if (rules.getBoolean ("verbose")) if (rules.getBoolean ("verbose"))
std::cout << intervalSummarize (database, rules, now); std::cout << intervalSummarize (database, rules, started);


database.endTransaction (); database.endTransaction ();


Expand Down
24 changes: 2 additions & 22 deletions src/data.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -214,9 +214,6 @@ Interval getFilter (const CLI& cli)
throw std::string ("Unrecognized date range: '") + join (" ", args) + "'."; throw std::string ("Unrecognized date range: '") + join (" ", args) + "'.";
} }


if (filter.start > now)
throw std::string ("Time tracking cannot be set in the future.");

if (filter.end != 0 && filter.start > filter.end) if (filter.end != 0 && filter.start > filter.end)
throw std::string ("The end of a date range must be after the start."); throw std::string ("The end of a date range must be after the start.");


Expand Down Expand Up @@ -386,24 +383,7 @@ std::vector <Interval> flatten (
Interval chunk {interval}; Interval chunk {interval};
chunk.setRange (result); chunk.setRange (result);


// Only historical data is included. all.push_back (chunk);
if (chunk.start <= now)
{
// Closed chunk ranges in the future need to be adjusted.
if (! chunk.is_open () &&
chunk.end > now)
{
// If the interval is open, so must be chunk.
if (interval.is_open ())
chunk.end = {0};

// Otherwise truncate to now.
else
chunk.end = now;
}

all.push_back (chunk);
}
} }


return all; return all;
Expand Down Expand Up @@ -568,7 +548,7 @@ bool matchesFilter (const Interval& interval, const Interval& filter)
} }


//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Take an interval and clip it to the // Take an interval and clip it to the range
Interval clip (const Interval& interval, const Range& range) Interval clip (const Interval& interval, const Range& range)
{ {
if (! range.is_started () || if (! range.is_started () ||
Expand Down

0 comments on commit 72cfe7b

Please sign in to comment.