diff --git a/AUTHORS b/AUTHORS index 203454d3..87c17ca3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -99,3 +99,4 @@ Thanks to the following, who submitted detailed bug reports and excellent sugges varac xerus2000 Rafael Oliveira + agentcoffee diff --git a/ChangeLog b/ChangeLog index c9a65fd5..4c69329b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,8 @@ - #470 Do not leak filter in IntervalFilterFirstOf (thanks to Shaun Ruffel) - #474 Make display of ids and annotations in summary report configurable +- #491 Tracking an interval in the future while actively tracking time results in a database inconsistency + (thanks to agentcoffee) ------ current release --------------------------- diff --git a/src/commands/CmdSummary.cpp b/src/commands/CmdSummary.cpp index e77abb8e..6b233d9a 100644 --- a/src/commands/CmdSummary.cpp +++ b/src/commands/CmdSummary.cpp @@ -122,9 +122,11 @@ int CmdSummary ( auto days_start = filter.is_started() ? filter.start : tracked.front ().start; auto days_end = filter.is_ended() ? filter.end : tracked.back ().end; + const auto now = Datetime (); + if (days_end == 0) { - days_end = Datetime (); + days_end = now; } for (Datetime day = days_start.startOfDay (); day < days_end; ++day) @@ -136,7 +138,7 @@ int CmdSummary ( for (auto& track : subset (day_range, tracked)) { // Make sure the track only represents one day. - if ((track.is_open () && day > Datetime ())) + if ((track.is_open () && day > now)) continue; row = table.addRow (); @@ -145,14 +147,22 @@ int CmdSummary ( { table.set (row, 0, format ("W{1}", day.week ())); table.set (row, 1, day.toString ("Y-M-D")); - table.set (row, 2, day.dayNameShort (day.dayOfWeek ())); + table.set (row, 2, Datetime::dayNameShort (day.dayOfWeek ())); previous = day; } + // Intersect track with day. auto today = day_range.intersect (track); - if (track.is_open () && day <= Datetime () && today.end > Datetime ()) - today.end = Datetime (); + + if (track.is_open() && track.start > now) + { + today.end = track.start; + } + else if (track.is_open () && day <= now && today.end > now) + { + today.end = now; + } std::string tags = join(", ", track.tags()); @@ -173,11 +183,13 @@ int CmdSummary ( table.set (row, (show_ids ? 5 : 4), annotation); } + const auto total = today.total (); + table.set (row, (show_ids ? 5 : 4) + offset, today.start.toString ("h:N:S")); table.set (row, (show_ids ? 6 : 5) + offset, (track.is_open () ? "-" : today.end.toString ("h:N:S"))); - table.set (row, (show_ids ? 7 : 6) + offset, Duration (today.total ()).formatHours ()); + table.set (row, (show_ids ? 7 : 6) + offset, Duration (total).formatHours ()); - daily_total += today.total (); + daily_total += total; } if (row != -1) diff --git a/src/helper.cpp b/src/helper.cpp index 901de476..cdb103e0 100644 --- a/src/helper.cpp +++ b/src/helper.cpp @@ -111,10 +111,20 @@ std::string intervalSummarize (const Rules& rules, const Interval& interval) // Interval open. if (interval.is_open ()) { - out << "Tracking " << tags << '\n' - << " Started " << interval.start.toISOLocalExtended () << '\n' - << " Current " << minimalDelta (interval.start, Datetime ()) << '\n' - << " Total " << std::setw (19) << std::setfill (' ') << total.formatHours () << '\n'; + auto now = Datetime (); + + if (interval.start <= now ) + { + out << "Tracking " << tags << '\n' + << " Started " << interval.start.toISOLocalExtended () << '\n' + << " Current " << minimalDelta (interval.start, now) << '\n' + << " Total " << std::setw (19) << std::setfill (' ') << total.formatHours () << '\n'; + } + else + { + out << "Tracking " << tags << '\n' + << " Starting " << interval.start.toISOLocalExtended () << '\n'; + } } // Interval closed.