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;