Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkersten2005-07-08 17:26:13 -0400
committermkersten2005-07-08 17:26:13 -0400
commit534cb459228f188cfb616f5883201ff05dfa92a2 (patch)
tree266a201a1977092e396f412098209933e29cb59d /org.eclipse.mylyn.tasks.ui
parenta7440a3e07514f360f0f4579611de0c94d18607e (diff)
downloadorg.eclipse.mylyn.tasks-534cb459228f188cfb616f5883201ff05dfa92a2.tar.gz
org.eclipse.mylyn.tasks-534cb459228f188cfb616f5883201ff05dfa92a2.tar.xz
org.eclipse.mylyn.tasks-534cb459228f188cfb616f5883201ff05dfa92a2.zip
Bugzilla Bug 102671
automatic elapsed time for tasks
Diffstat (limited to 'org.eclipse.mylyn.tasks.ui')
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ITask.java2
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/Task.java95
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskSummaryEditor.java2
3 files changed, 82 insertions, 17 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ITask.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ITask.java
index 7380741d2..91ba7e260 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ITask.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ITask.java
@@ -94,4 +94,6 @@ public interface ITask extends Serializable {
public abstract void setCategory(TaskCategory cat);
public abstract TaskCategory getCategory();
+
+ public abstract String getElapsedTimeForDisplay();
} \ No newline at end of file
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/Task.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/Task.java
index f42af515b..79c4e3692 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/Task.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/Task.java
@@ -48,12 +48,12 @@ public class Task implements ITask, ITaskListElement {
private String priority = "P3";
private String notes = "";
private String estimatedTime = "";
- private String elapsedTime = "";
+// private String elapsedTime = "";
private boolean completed;
private RelatedLinks links = new RelatedLinks();
private TaskCategory parentCategory = null;
- private Date activeStart = null;
+ private Date timeActivated = null;
private long elapsed;
/**
* null if root
@@ -114,21 +114,24 @@ public class Task implements ITask, ITaskListElement {
* Package visible in order to prevent sets that don't update the index.
*/
public void setActive(boolean active) {
+ this.active = active;
if (active) {
- activeStart = new Date();
+ timeActivated = new Date();
} else {
calculateElapsedTime();
- activeStart = null;
- }
- this.active = active;
+ timeActivated = null;
+ }
}
private void calculateElapsedTime() {
- if (activeStart == null)
+ if (timeActivated == null)
return;
- long elapsedMin = new Date().getTime() - activeStart.getTime();
- long min = 1000*60;
- this.elapsed += elapsedMin / min;
+ elapsed += new Date().getTime() - timeActivated.getTime();
+ if (isActive()) {
+ timeActivated = new Date();
+ } else {
+ timeActivated = null;
+ }
}
public boolean isActive() {
@@ -256,15 +259,18 @@ public class Task implements ITask, ITaskListElement {
}
public String getElapsedTime() {
- if (elapsedTime == "" && activeStart != null) {
- calculateElapsedTime();
-
+ if (isActive()) {
+ calculateElapsedTime();
}
- return elapsedTime;
+ return "" + elapsed;
}
- public void setElapsedTime(String elapsed) {
- this.elapsedTime = elapsed;
+ public void setElapsedTime(String elapsedString) {
+ if (elapsedString.equals("")) {
+ elapsed = 0;
+ } else {
+ elapsed = Long.parseLong(elapsedString);
+ }
}
public String getEstimatedTime() {
@@ -313,4 +319,61 @@ public class Task implements ITask, ITaskListElement {
return MylarImages.getImage(MylarImages.TASK_INACTIVE);
}
}
+
+ public String getElapsedTimeForDisplay() {
+ long seconds = elapsed / 1000;
+ long minutes = 0;
+ long hours = 0;
+// final long SECOND = 1000;
+ final long MIN = 60;
+ final long HOUR = MIN * 60;
+
+ String hour = "";
+ String min = "";
+ String sec = "";
+ if (seconds >= HOUR) {
+ hours = seconds / HOUR;
+ if (hours == 1) {
+ hour = hours + " hour ";
+ } else if (hours > 1) {
+ hour = hours + " hours ";
+ }
+ seconds -= hours * HOUR;
+
+ minutes = seconds / MIN;
+ if (minutes == 1) {
+ min = minutes + " minute ";
+ } else if (minutes > 1) {
+ min = minutes + " minutes ";
+ }
+// seconds -= minutes * MIN;
+// if (seconds == 1) {
+// sec = seconds + " second";
+// } else if (seconds > 1) {
+// sec = seconds + " seconds";
+// }
+ return hour + min + sec;
+ } else if (seconds >= MIN) {
+ minutes = seconds / MIN;
+ if (minutes == 1) {
+ min = minutes + " minute ";
+ } else if (minutes > 1) {
+ min = minutes + " minutes ";
+ }
+// seconds -= minutes * MIN;
+// if (seconds == 1) {
+// sec = seconds + " second";
+// } else if (seconds > 1) {
+// sec = seconds + " seconds";
+// }
+ return min + sec;
+ } else {
+// if (seconds == 1) {
+// sec = seconds + " second";
+// } else if (seconds > 1) {
+// sec = seconds + " seconds";
+// }
+ return sec;
+ }
+ }
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskSummaryEditor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskSummaryEditor.java
index bddddb259..7ab14f26b 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskSummaryEditor.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskSummaryEditor.java
@@ -422,7 +422,7 @@ public class TaskSummaryEditor extends EditorPart {
l = toolkit.createLabel(container, "Elapsed Time:");
l.setForeground(toolkit.getColors().getColor(FormColors.TITLE));
- Text text2 = toolkit.createText(container,task.getElapsedTime(), SWT.BORDER);
+ Text text2 = toolkit.createText(container,task.getElapsedTimeForDisplay(), SWT.BORDER);
text2.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
text2.setEditable(false);
text2.setEnabled(false);

Back to the top