Skip to content

Commit

Permalink
Level-8 deadline done, event left to do
Browse files Browse the repository at this point in the history
  • Loading branch information
jellywaiyan committed Sep 3, 2023
1 parent 8708c8a commit a6a9d84
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 6 deletions.
65 changes: 63 additions & 2 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,79 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.List;

public class Deadline extends Task {

protected String by;

protected LocalDate deadlineDate;

protected LocalDateTime deadLineDateAndTime;

public Deadline(String description, String by) {
super(description);
this.deadlineDate = parseDate(by);
this.deadLineDateAndTime = parseDateTime(by);
this.by = by;
}

@Override
public String toString() {
return "[D]" + super.toString() + "(by: " + by + ")";
if (deadlineDate != null) {
String outputDate = deadlineDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy"));
return "[D]" + super.toString() + "(by: " + outputDate + ")";
} else if (deadLineDateAndTime != null) {
String outputDate = deadLineDateAndTime.format(DateTimeFormatter.ofPattern("MMM dd yyyy HH:mm"));
return "[D]" + super.toString() + "(by: " + outputDate + ")";
} else {
return "[D]" + super.toString() + "(by: " + by + ")";
}
}
@Override
public String writeToFile() {
return "D | " + (getIsDone() ? "1" : "0") + " | " + getDescription() + " | " + by;
String printedStuff = "D | " + (getIsDone() ? "1" : "0") + " | " + getDescription() + " | ";
if (deadlineDate != null) {
return printedStuff + this.deadlineDate;
} else if (deadLineDateAndTime != null) {
return printedStuff + this.deadLineDateAndTime;
} else {
return printedStuff + this.by;
}
}

protected LocalDate parseDate(String date) {
List<DateTimeFormatter> formats = new ArrayList<>();
formats.add(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
formats.add(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
formats.add(DateTimeFormatter.ofPattern("d/M/yyyy"));

for (int i = 0; i < formats.size(); i++) {
try {
return LocalDate.parse(date, formats.get(i));
} catch (DateTimeParseException e) {

}
}
return null;
}

protected LocalDateTime parseDateTime(String date) {
List<DateTimeFormatter> formats = new ArrayList<>();
formats.add(DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm"));
formats.add(DateTimeFormatter.ofPattern("dd/MM/yyyy HHmm"));
formats.add(DateTimeFormatter.ofPattern("d/MM/yyyy HHmm"));

for (int i = 0; i < formats.size(); i++) {
try {
return LocalDateTime.parse(date, formats.get(i));
} catch (DateTimeParseException e) {

}
}

return null;
}
}
9 changes: 9 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import java.time.LocalDate;
import java.time.LocalDateTime;

public class Event extends Task {

protected String from;
protected String to;

protected LocalDate fromDate;
protected LocalDate toDate;

protected LocalDateTime fromDateTime;
protected LocalDateTime toDateTime;

public Event(String description, String from, String to) {
super(description);
this.from = from;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/Jelly.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import exceptions.JellyUnknownCommandException;
import java.io.File;
import java.io.FileWriter;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;


public class Jelly {
private static final String FILE_PATH = "./taskData/jelly.txt";
Expand Down
5 changes: 1 addition & 4 deletions taskData/jelly.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
T | 0 | this
D | 1 | that | 2pm mondayee
E | 0 | party | 2pm sunday to 3pm monday
T | 1 | thing that
D | 0 | do this | 2020-02-12T18:00

0 comments on commit a6a9d84

Please sign in to comment.