Skip to content

Commit

Permalink
Merge branch 'branch-Level-8'
Browse files Browse the repository at this point in the history
  • Loading branch information
jellywaiyan committed Sep 3, 2023
2 parents 4dbc78f + 7196ad9 commit 8418609
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 8 deletions.
60 changes: 58 additions & 2 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,74 @@
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 outputDateTime = deadLineDateAndTime.format(DateTimeFormatter.ofPattern("MMM dd yyyy HH:mm"));
return "[D]" + super.toString() + "(by: " + outputDateTime + ")";
} 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() + "| ";
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"));
formats.add(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm"));

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

}
}

return null;
}
}
69 changes: 67 additions & 2 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,85 @@
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 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.fromDate = parseDate(from);
this.toDate = parseDate(to);
this.fromDateTime = parseDateTime(from);
this.toDateTime = parseDateTime(to);
this.from = from;
this.to = to;
}

@Override
public String toString() {
return "[E]" + super.toString() + "(from: " + from + " to: " + to + ")";
String fromWhen = from;
String toWhen = to;

if (fromDate != null) {
fromWhen = fromDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy"));
} else if (fromDateTime != null) {
fromWhen = fromDateTime.format(DateTimeFormatter.ofPattern("MMM dd yyyy HH:mm"));
}

if (toDate != null) {
toWhen = toDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy"));
} else if (toDateTime != null) {
toWhen = toDateTime.format(DateTimeFormatter.ofPattern("MMM dd yyyy HH:mm"));
}
return "[E]" + super.toString() + "(from: " + fromWhen + " to: " + toWhen + ")";
}
@Override
public String writeToFile() {
return "E | " + (getIsDone() ? "1" : "0") + " | " + getDescription() + " | " + from + " to " + to;
return "E | " + (getIsDone() ? "1" : "0") + " | " + getDescription() + "| " + from + " to " + to;
}

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"));
formats.add(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm"));

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

}
}

return null;
}
}
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
6 changes: 2 additions & 4 deletions taskData/jelly.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
T | 0 | this
D | 1 | that | 2pm mondayee
E | 0 | party | 2pm sunday to 3pm monday
T | 1 | thing that
E | 0 | do this | 20/12/2020 1900 to 21/12/2020 1001
D | 1 | finish this | 1/02/1990 0001

0 comments on commit 8418609

Please sign in to comment.