Skip to content

Commit

Permalink
update xml adapted task to store time
Browse files Browse the repository at this point in the history
  • Loading branch information
rachx committed Oct 15, 2016
1 parent 6c430a4 commit 1781e7b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/seedu/agendum/storage/XmlAdaptedTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,27 @@
import seedu.agendum.model.task.*;

import javax.xml.bind.annotation.XmlElement;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
* JAXB-friendly version of the Task.
*/
public class XmlAdaptedTask {

private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
@XmlElement(required = true)
private String name;
@XmlElement(required = true)
private String isCompleted;
@XmlElement(required = false)
private String startDateTime;
@XmlElement(required = false)
private String endDateTime;

@XmlElement
private List<XmlAdaptedTag> tagged = new ArrayList<>();
Expand All @@ -37,6 +46,12 @@ public XmlAdaptedTask(ReadOnlyTask source) {
name = source.getName().fullName;
isCompleted = Boolean.toString(source.isCompleted());
tagged = new ArrayList<>();
if (source.getStartDateTime().isPresent()) {
startDateTime = source.getStartDateTime().get().format(formatter);
}
if (source.getEndDateTime().isPresent()) {
endDateTime = source.getEndDateTime().get().format(formatter);
}
for (Tag tag : source.getTags()) {
tagged.add(new XmlAdaptedTag(tag));
}
Expand All @@ -60,6 +75,12 @@ public Task toModelType() throws IllegalValueException {
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;
}
}

0 comments on commit 1781e7b

Please sign in to comment.