diff --git a/src/Task.cpp b/src/Task.cpp index 40f33b90b..afef355b7 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -762,12 +762,21 @@ void Task::setAnnotations (const std::map & annotation // The timestamp is part of the name: // annotation_1234567890:"..." // +// Note that the time is incremented (one second) in order to find a unique +// timestamp. void Task::addAnnotation (const std::string& description) { - std::stringstream s; - s << "annotation_" << time (NULL); + time_t now = time (NULL); + std::string key; - (*this)[s.str ()] = description; + do + { + key = "annotation_" + format ((int) now); + ++now; + } + while (has (key)); + + (*this)[key] = description; recalc_urgency = true; } diff --git a/test/annotate.t b/test/annotate.t index 982f85014..fc4d49a54 100755 --- a/test/annotate.t +++ b/test/annotate.t @@ -51,16 +51,10 @@ qx{../src/task rc:annotate.rc add two}; qx{../src/task rc:annotate.rc add three}; qx{../src/task rc:annotate.rc add four}; qx{../src/task rc:annotate.rc 1 annotate foo1}; -diag ("5 second delay"); -sleep 1; qx{../src/task rc:annotate.rc 1 annotate foo2}; -sleep 1; qx{../src/task rc:annotate.rc 1 annotate foo3}; -sleep 1; qx{../src/task rc:annotate.rc 2 annotate bar1}; -sleep 1; qx{../src/task rc:annotate.rc 2 annotate bar2}; -sleep 1; qx{../src/task rc:annotate.rc 3 annotate baz1}; my $output = qx{../src/task rc:annotate.rc rrr}; diff --git a/test/bug.703.t b/test/bug.703.t index 484891a64..bd7b1a138 100755 --- a/test/bug.703.t +++ b/test/bug.703.t @@ -42,12 +42,9 @@ if (open my $fh, '>', 'bug.rc') # Bug 703: /from/t/g fails to make all changes to annotations # Setup: Add a few tasks -diag ("2 second delay"); qx{../src/task rc:bug.rc add This is a test}; qx{../src/task rc:bug.rc 1 annotate Annotation one}; -sleep 1; qx{../src/task rc:bug.rc 1 annotate Annotation two}; -sleep 1; qx{../src/task rc:bug.rc 1 annotate Annotation three}; my $output = qx{../src/task rc:bug.rc list}; diff --git a/test/bug.hasnt.t b/test/bug.hasnt.t index 29c1ff13e..38f0a69f9 100755 --- a/test/bug.hasnt.t +++ b/test/bug.hasnt.t @@ -49,8 +49,6 @@ qx{../src/task rc:hasnt.rc 2 annotate bar}; # 3 qx{../src/task rc:hasnt.rc add foo}; qx{../src/task rc:hasnt.rc 3 annotate bar}; -diag ("3 second delay"); -sleep 1; qx{../src/task rc:hasnt.rc 3 annotate baz}; # 4 @@ -63,13 +61,11 @@ qx{../src/task rc:hasnt.rc 5 annotate foo}; # 6 qx{../src/task rc:hasnt.rc add bar}; qx{../src/task rc:hasnt.rc 6 annotate foo}; -sleep 1; qx{../src/task rc:hasnt.rc 6 annotate baz}; #7 qx{../src/task rc:hasnt.rc add one}; qx{../src/task rc:hasnt.rc 7 annotate two}; -sleep 1; qx{../src/task rc:hasnt.rc 7 annotate three}; my $output = qx{../src/task rc:hasnt.rc ls description.has:foo}; diff --git a/test/denotate.t b/test/denotate.t index 5157b5e6e..40ae7713f 100755 --- a/test/denotate.t +++ b/test/denotate.t @@ -47,18 +47,11 @@ if (open my $fh, '>', 'denotate.rc') # Add four tasks, annotate one three times, one twice, one just once and one none. qx{../src/task rc:denotate.rc add one}; qx{../src/task rc:denotate.rc 1 annotate Ernie}; -diag ("6 second delay"); -sleep 1; qx{../src/task rc:denotate.rc 1 annotate Bert}; -sleep 1; qx{../src/task rc:denotate.rc 1 annotate Bibo}; -sleep 1; qx{../src/task rc:denotate.rc 1 annotate Kermit the frog}; -sleep 1; qx{../src/task rc:denotate.rc 1 annotate Kermit the frog}; -sleep 1; qx{../src/task rc:denotate.rc 1 annotate Kermit}; -sleep 1; qx{../src/task rc:denotate.rc 1 annotate Kermit and Miss Piggy}; my $output = qx{../src/task rc:denotate.rc rrr}; diff --git a/test/urgency.t b/test/urgency.t index 4e95d45ec..5d0835ef9 100755 --- a/test/urgency.t +++ b/test/urgency.t @@ -120,22 +120,15 @@ qx{../src/task rc:urgency.rc add 6a}; # task 12 qx{../src/task rc:urgency.rc 12 annotate A}; qx{../src/task rc:urgency.rc add 6b}; # task 13 qx{../src/task rc:urgency.rc 13 annotate A}; -diag ("6 second delay"); -sleep 1; qx{../src/task rc:urgency.rc 13 annotate B}; qx{../src/task rc:urgency.rc add 6c}; # task 14 qx{../src/task rc:urgency.rc 14 annotate A}; -sleep 1; qx{../src/task rc:urgency.rc 14 annotate B}; -sleep 1; qx{../src/task rc:urgency.rc 14 annotate C}; qx{../src/task rc:urgency.rc add 6d}; # task 15 qx{../src/task rc:urgency.rc 15 annotate A}; -sleep 1; qx{../src/task rc:urgency.rc 15 annotate B}; -sleep 1; qx{../src/task rc:urgency.rc 15 annotate C}; -sleep 1; qx{../src/task rc:urgency.rc 15 annotate D}; # annotations: 8 (1 annotation) + 10 (pending)