From 023cc3c383150b31701299a1ac675ea0129f7353 Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Sun, 6 Sep 2015 23:20:51 +0200 Subject: [PATCH] CmdEdit: Do not bump annotation timestamps without need --- src/commands/CmdEdit.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/commands/CmdEdit.cpp b/src/commands/CmdEdit.cpp index 8a146954c..8224b409b 100644 --- a/src/commands/CmdEdit.cpp +++ b/src/commands/CmdEdit.cpp @@ -644,13 +644,20 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string // if there is no corresponding id, then a new unique date is created). Date when (value.substr (0, gap), dateformat); - // This guarantees that if more than one annotation has the same date, - // that the seconds will be different, thus unique, thus not squashed. - // Bug #249 - when += (const int) annotations.size (); + // If the map already contains a annotation for a given timestamp + // we need to increment until we find an unused key + int timestamp = (int) when.toEpoch (); std::stringstream name; - name << "annotation_" << when.toEpoch (); + + do + { + name.str (""); // Clear + name << "annotation_" << timestamp; + timestamp++; + } + while (annotations.find (name.str ()) != annotations.end ()); + std::string text = trim (value.substr (gap + 4), "\t "); annotations.insert (std::make_pair (name.str (), json::decode (text))); }