Skip to content

Commit

Permalink
B-DoAfterTasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Yu Jiahan committed Sep 18, 2019
1 parent fe14568 commit a7098b6
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/main/java/duke/task/DoAfter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package duke.task;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;

/**
* Represents a special task that {@link Task } specified by the due {@link Date}
*/
public class DoAfter extends Task{

private String after;
private Date date;

/**
* CONSTRUCTOR
* by specifying the description of this task
* and the description of the task
* after which this task need to be done
*/
public DoAfter(String description, Task todo) {
super(description);
this.after = todo.getDescription();
}

/**
* CONSTRUCTOR
* by specifying the description of this task
* and the date/time after which this task need to be done
*/
public DoAfter(String description, String after) {
super(description);
this.after = after;
this.date = super.getDate(after);
}

@Override
public String toString() {
return (date == null) ? "[A]" + super.toString() + "(after: " + after + ")" : "[A]" + super.toString() + "(after: " + getDateString(date) + ")";
}

/**
* Returns the {@link Date } instance as a String to be printed in the file
* @param date deadline {@link Date} for finishing the task
* @return String the date for the deadline
*/
private String getDateString(Date date) {
if (date == null)
return after;
LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
String pattern = after.length() > 11 ? "d'" + getDaySuffix(localDate.getDayOfMonth()) + "' 'of' MMMM yyyy, ha " : "d'" + getDaySuffix(localDate.getDayOfMonth()) + "' 'of' MMMM yyyy";
SimpleDateFormat formatter = new SimpleDateFormat(pattern);
return formatter.format(date);
}

/**
* Returns the String representation of the {@link Deadline} in format compatible to be easily read and written in a text file on the hard disc
* @return String used to print the {@link Task } in the text file
*/
public String printInFile() {
return this.isDone() ? "A|1|" + this.getDescription() + "| after" + this.after : "A|0|" + this.getDescription() + "| after" + this.after;
}


}

0 comments on commit a7098b6

Please sign in to comment.