From 31ca15c65a9af1bcfb08ab2ab7ed0aaa3061710f Mon Sep 17 00:00:00 2001 From: IndrekV Date: Tue, 13 Mar 2018 15:03:36 +0200 Subject: [PATCH] Only discard time entries that are running (lib) --- src/time_entry.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/time_entry.cc b/src/time_entry.cc index 601225797a..78f20973e0 100644 --- a/src/time_entry.cc +++ b/src/time_entry.cc @@ -101,16 +101,23 @@ bool TimeEntry::billableIsAPremiumFeature(const error err) const { } void TimeEntry::DiscardAt(const Poco::UInt64 at) { + if (!IsTracking()) { + logger().error("Cannot discard time entry that is not tracking"); + return; + } + if (!at) { logger().error("Cannot discard time entry without a timestamp"); return; } - Poco::Int64 duration = at + DurationInSeconds(); - if (duration < 0) { - duration = -1 * duration; + if (at < Start()) { + logger().error("Cannot discard time entry with start time bigger than current moment"); + return; } + Poco::Int64 duration = at - Start(); + if (duration < 0) { logger().error("Discarding with this time entry would result in negative duration"); // NOLINT return;