Skip to content

Commit

Permalink
add last updated time
Browse files Browse the repository at this point in the history
  • Loading branch information
rachx committed Oct 26, 2016
2 parents d50fb7e + f3c56f9 commit 96e901a
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/main/java/seedu/agendum/model/task/ReadOnlyTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ public interface ReadOnlyTask {
String getPeriod();
Optional<LocalDateTime> getStartDateTime();
Optional<LocalDateTime> getEndDateTime();


ChildRecurringTask getChild();
RecurringTask getParent();

LocalDateTime getLastUpdatedTime();


/**
* Returns true if both have the same state. (interfaces cannot override .equals)
*/
Expand Down Expand Up @@ -64,7 +68,9 @@ default String getDetailedText() {
.append(" Start Time: ")
.append(startTime)
.append(" End Time: ")
.append(endTime);
.append(endTime)
.append(" Last Updated Time: ")
.append(getLastUpdatedTime().toString());
return builder.toString();
}
}
43 changes: 43 additions & 0 deletions src/main/java/seedu/agendum/model/task/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import seedu.agendum.logic.parser.DateTimeParser;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Objects;
import java.util.Optional;

Expand All @@ -21,6 +22,7 @@ public class Task implements ReadOnlyTask, Comparable<Task> {
private boolean isChild;
private LocalDateTime startDateTime;
private LocalDateTime endDateTime;
private LocalDateTime lastUpdatedTime;

// ================ Constructor methods ==============================

Expand All @@ -35,6 +37,9 @@ public Task(Name name) {
this.endDateTime = null;
this.isRecurring = false;
this.isChild = false;

setLastUpdatedTimeToNow();

}

/**
Expand All @@ -47,7 +52,11 @@ public Task(Name name, Optional<LocalDateTime> deadline) {
this.isRecurring = false;
this.startDateTime = null;
this.endDateTime = deadline.orElse(null);

this.isChild = false;

setLastUpdatedTimeToNow();

}

/**
Expand All @@ -62,6 +71,7 @@ public Task(Name name, Optional<LocalDateTime> startDateTime,
this.startDateTime = startDateTime.orElse(null);
this.endDateTime = endDateTime.orElse(null);
this.isChild = false;
setLastUpdatedTimeToNow();
}

/**
Expand All @@ -72,6 +82,7 @@ public Task(ReadOnlyTask source) {
if (source.isCompleted()) {
this.markAsCompleted();
}
setLastUpdatedTime(source.getLastUpdatedTime());
}

public Task(RecurringTask task) {}
Expand Down Expand Up @@ -118,6 +129,11 @@ public Optional<LocalDateTime> getEndDateTime() {
return Optional.ofNullable(endDateTime);
}

@Override
public LocalDateTime getLastUpdatedTime() {
return lastUpdatedTime;
}

/**
* Pre-condition: Task has a start or end time
* Return the (earlier) time associated with the task (assumed to be start time)
Expand All @@ -131,22 +147,35 @@ private LocalDateTime getTaskTime() {

public void setName(Name name) {
this.name = name;
setLastUpdatedTimeToNow();
}

public void markAsCompleted() {
this.isCompleted = true;
setLastUpdatedTimeToNow();
}

public void markAsUncompleted() {
this.isCompleted = false;
setLastUpdatedTimeToNow();
}

public void setStartDateTime(Optional<LocalDateTime> startDateTime) {
this.startDateTime = startDateTime.orElse(null);
setLastUpdatedTimeToNow();
}

public void setEndDateTime(Optional<LocalDateTime> endDateTime) {
this.endDateTime = endDateTime.orElse(null);
setLastUpdatedTimeToNow();
}

public void setLastUpdatedTime(LocalDateTime updatedTime) {
this.lastUpdatedTime = updatedTime;
}

public void setLastUpdatedTimeToNow() {
this.lastUpdatedTime = LocalDateTime.now();
}

// ================ Other methods ==============================
Expand All @@ -169,6 +198,11 @@ public int compareTo(Task other) {
if (comparedTime != 0) {
return comparedTime;
}

int comparedLastUpdatedTime = compareLastUpdatedTime(other);
if (comparedLastUpdatedTime != 0) {
return comparedLastUpdatedTime;
}

return compareName(other);
}
Expand All @@ -189,6 +223,15 @@ public int compareTime(Task other) {
}
}

public int compareLastUpdatedTime(Task other) {
// to fix erratic behavior for logic manager test
long seconds = ChronoUnit.SECONDS.between(this.getLastUpdatedTime(), other.getLastUpdatedTime());
if (Math.abs(seconds) < 2) {
return 0;
}
return other.getLastUpdatedTime().compareTo(this.getLastUpdatedTime());
}

public int compareName(Task other) {
return this.getName().toString().compareTo(other.getName().toString());
}
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/seedu/agendum/storage/XmlAdaptedTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
public class XmlAdaptedTask {

private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@XmlElement(required = true)
private String name;
@XmlElement(required = true)
Expand All @@ -25,6 +25,8 @@ public class XmlAdaptedTask {
private String isRecurring;
@XmlElement(required = true)
private String isChild;
@XmlElement(required = true)
private String lastUpdatedTime;
@XmlElement(required = false)
private String startDateTime;
@XmlElement(required = false)
Expand All @@ -49,11 +51,15 @@ public XmlAdaptedTask(ReadOnlyTask source) {
name = source.getName().fullName;
isRecurring = Boolean.toString(source.isRecurring());
isCompleted = Boolean.toString(source.isCompleted());

isChild = Boolean.toString(source.isChild());

lastUpdatedTime = source.getLastUpdatedTime().format(formatter);

if (source.getStartDateTime().isPresent()) {
startDateTime = source.getStartDateTime().get().format(formatter);
}

if (source.getEndDateTime().isPresent()) {
endDateTime = source.getEndDateTime().get().format(formatter);
}
Expand All @@ -73,17 +79,22 @@ public XmlAdaptedTask(ReadOnlyTask source) {
public Task toTaskModelType() throws IllegalValueException {
final Name name = new Name(this.name);
final boolean markedAsCompleted = Boolean.valueOf(isCompleted);

Task newTask = new Task(name);
newTask.setLastUpdatedTime(LocalDateTime.parse(this.lastUpdatedTime, formatter));

if (markedAsCompleted) {
newTask.markAsCompleted();
}

if (startDateTime != null) {
newTask.setStartDateTime(Optional.ofNullable(LocalDateTime.parse(this.startDateTime, formatter)));
}

if (endDateTime != null) {
newTask.setEndDateTime(Optional.ofNullable(LocalDateTime.parse(this.endDateTime, formatter)));
}

return newTask;
}

Expand Down
9 changes: 9 additions & 0 deletions src/test/data/XmlUtilTest/validToDoList.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,38 @@
<todolist>
<tasks>
<name>Hans Muster</name>
<lastUpdatedTime>2016-10-10 10:10:00</lastUpdatedTime>
</tasks>
<tasks>
<name>Ruth Mueller</name>
<lastUpdatedTime>2016-10-10 10:10:00</lastUpdatedTime>
</tasks>
<tasks>
<name>Heinz Kurz</name>
<lastUpdatedTime>2016-10-10 10:10:00</lastUpdatedTime>
</tasks>
<tasks>
<name>Cornelia Meier</name>
<lastUpdatedTime>2016-10-10 10:10:00</lastUpdatedTime>
</tasks>
<tasks>
<name>Werner Meyer</name>
<lastUpdatedTime>2016-10-10 10:10:00</lastUpdatedTime>
</tasks>
<tasks>
<name>Lydia Kunz</name>
<lastUpdatedTime>2016-10-10 10:10:00</lastUpdatedTime>
</tasks>
<tasks>
<name>Anna Best</name>
<lastUpdatedTime>2016-10-10 10:10:00</lastUpdatedTime>
</tasks>
<tasks>
<name>Stefan Meier</name>
<lastUpdatedTime>2016-10-10 10:10:00</lastUpdatedTime>
</tasks>
<tasks>
<name>Martin Mueller</name>
<lastUpdatedTime>2016-10-10 10:10:00</lastUpdatedTime>
</tasks>
</todolist>
25 changes: 19 additions & 6 deletions src/test/java/seedu/agendum/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ public void execute_mark_marksCorrectSingleTaskAsCompleted() throws Exception {
expectedTDL.markTask(threeTasks.get(0));

// prepare model
model.resetData(new ToDoList());
helper.addToModel(model, threeTasks);

// prepare for message
Expand Down Expand Up @@ -552,10 +553,11 @@ public void execute_mark_marksCorrectRangeOfTasks() throws Exception {

// prepare expected TDL
ToDoList expectedTDL = helper.generateToDoList(fourTasks);
expectedTDL.markTask(fourTasks.get(3));
expectedTDL.markTask(fourTasks.get(2));
expectedTDL.markTask(fourTasks.get(3));

// prepare model
model.resetData(new ToDoList());
helper.addToModel(model, fourTasks);

// prepare for message
Expand All @@ -578,9 +580,9 @@ public void execute_mark_marksCorrectMultipleTasks() throws Exception {

// prepare expected TDL
ToDoList expectedTDL = helper.generateToDoList(fourTasks);
expectedTDL.markTask(fourTasks.get(3));
expectedTDL.markTask(fourTasks.get(2));
expectedTDL.markTask(fourTasks.get(1));
expectedTDL.markTask(fourTasks.get(2));
expectedTDL.markTask(fourTasks.get(3));

// prepare model
helper.addToModel(model, fourTasks);
Expand Down Expand Up @@ -620,6 +622,7 @@ public void execute_unmark_unmarksCorrectSingleTaskFromCompleted() throws Except
expectedTDL.unmarkTask(threeTasks.get(2));

// prepare model
model.resetData(new ToDoList());
helper.addToModel(model, threeTasks);

// prepare for message
Expand Down Expand Up @@ -686,6 +689,7 @@ public void execute_unmark_unmarksCorrectRangeOfTasks() throws Exception {
expectedTDL.unmarkTask(fourTasks.get(3));

// prepare model
model.resetData(new ToDoList());
helper.addToModel(model, fourTasks);

// prepare for message
Expand Down Expand Up @@ -1067,9 +1071,13 @@ public void execute_load_successful() throws Exception {
*/
class TestDataHelper{

private LocalDateTime fixedTime = LocalDateTime.of(2016, 10, 10, 10, 10);

Task adam() throws Exception {
Name name = new Name("Adam Brown");
return new Task(name);
Task adam = new Task(name);
adam.setLastUpdatedTime(fixedTime);
return adam;
}

RecurringTask recurringAdam() throws Exception {
Expand All @@ -1085,9 +1093,11 @@ RecurringTask recurringAdam() throws Exception {
* @param seed used to generate the task data field values
*/
Task generateTask(int seed) throws Exception {
return new Task(
Task task = new Task(
new Name("Task " + seed)
);
task.setLastUpdatedTime(fixedTime);
return task;
}

/**
Expand All @@ -1096,16 +1106,19 @@ Task generateTask(int seed) throws Exception {
Task generateCompletedTask(int seed) throws Exception {
Task newTask = generateTask(seed);
newTask.markAsCompleted();
newTask.setLastUpdatedTime(fixedTime);
return newTask;
}

/**
* Generates a Task object with given name. Other fields will have some dummy values.
*/
Task generateTaskWithName(String name) throws Exception {
return new Task(
Task namedTask = new Task(
new Name(name)
);
namedTask.setLastUpdatedTime(fixedTime);
return namedTask;
}

/** Generates the correct add command based on the task given */
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/seedu/agendum/testutil/TestTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class TestTask implements ReadOnlyTask {
private boolean isCompleted;
private LocalDateTime startDateTime;
private LocalDateTime endDateTime;
private LocalDateTime lastUpdatedTime = LocalDateTime.of(2016, 10, 10, 10, 10);

public TestTask() {
isCompleted = false;
Expand All @@ -31,6 +32,7 @@ public TestTask(TestTask other) {
this.isCompleted = other.isCompleted;
this.startDateTime = other.startDateTime;
this.endDateTime = other.endDateTime;
this.lastUpdatedTime = other.getLastUpdatedTime();
}

public void setName(Name name) {
Expand Down Expand Up @@ -87,6 +89,11 @@ public Optional<LocalDateTime> getStartDateTime() {
public Optional<LocalDateTime> getEndDateTime() {
return Optional.ofNullable(endDateTime);
}

@Override
public LocalDateTime getLastUpdatedTime() {
return lastUpdatedTime;
}

/**
* Pre-condition: Task has a start or end time
Expand Down

0 comments on commit 96e901a

Please sign in to comment.