package seedu.task.storage;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlElement;

import seedu.task.commons.exceptions.IllegalValueException;
import seedu.task.model.tag.Tag;
import seedu.task.model.tag.UniqueTagList;
import seedu.task.model.task.Description;
import seedu.task.model.task.ReadOnlyTask;
import seedu.task.model.task.Task;

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

    @XmlElement(required = true)
    private String description;

    @XmlElement
    private List<XmlAdaptedTag> tagged = new ArrayList<>();

    /**
     * Constructs an XmlAdaptedTask.
     * This is the no-arg constructor that is required by JAXB.
     */
    public XmlAdaptedTask() {}


    /**
     * Converts a given Task into this class for JAXB use.
     *
     * @param source future changes to this will not affect the created XmlAdaptedTask
     */
    public XmlAdaptedTask(ReadOnlyTask source) {
        description = source.getDescription().description;
        tagged = new ArrayList<>();
        for (Tag tag : source.getTags()) {
            tagged.add(new XmlAdaptedTag(tag));
        }
    }

    /**
     * Converts this jaxb-friendly adapted task object into the model's Task object.
     *
     * @throws IllegalValueException if there were any data constraints violated in the adapted task
     */
    public Task toModelType() throws IllegalValueException {
        final List<Tag> taskTags = new ArrayList<>();
        for (XmlAdaptedTag tag : tagged) {
            taskTags.add(tag.toModelType());
        }
        final Description description = new Description(this.description);
        final UniqueTagList tags = new UniqueTagList(taskTags);
        return new Task(description, null, tags);
    }
}

@@ -294,24 +294,63 @@
 escription;%0A
+import seedu.task.model.task.Duration;%0A
 import seedu
@@ -380,16 +380,16 @@
 lyTask;%0A
-
 import s
@@ -557,16 +557,134 @@
 ription;
+%0A    @XmlElement(required = false)%0A    private String start;%0A    @XmlElement(required = false)%0A    private String end;
 %0A%0A    @X
@@ -1177,24 +1177,208 @@
 escription;%0A
+        Duration duration = source.getDuration();%0A        start = duration != null ? duration.getStartString() : null;%0A        end = duration != null ? duration.getEndString() : null;%0A
         tagg
@@ -2006,16 +2006,158 @@
 ption);%0A
+        final Duration duration = this.start != null && this.end != null ?%0A            new Duration(this.start, this.end) :%0A            null;%0A
         
@@ -2249,20 +2249,24 @@
 iption, 
-null
+duration
 , tags);

Fix saving of durations in database