Skip to content

Commit

Permalink
change dates to MMM dd yyyy format
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccalaujx committed Aug 30, 2021
1 parent 1cbdef7 commit e6a51b1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
15 changes: 13 additions & 2 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

public class Deadline extends Task {

protected String by;
protected String date = "";

public Deadline(String description, String by) throws DukeException {
super(description);
this.by = by;

try {
LocalDate localDate = LocalDate.parse(by);
this.date = localDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy"));
} catch (DateTimeParseException e) {
throw new DukeException("Deadline should be in a yyyy-mm-dd format.");
}

if (description.isEmpty() || description == "" || description == " ") {
throw new DukeException("☹ OOPS!!! The description of a deadline cannot be empty.");
Expand All @@ -15,7 +26,7 @@ public Deadline(String description, String by) throws DukeException {
if (by.isEmpty() || by == "" || by == " ") {
throw new DukeException("☹ OOPS!!! The deadline of this task must be indicated.");
} else {
this.by = by.substring(1);
this.by = this.date;
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static void main(String[] args) {
String taskDesc = input.replaceFirst("^deadline", "").split(" /")[0];
String deadline = "";
if (input.contains("/by")) {
deadline = input.substring(input.indexOf("/by") + 3);
deadline = input.substring(input.indexOf("/by") + 4);
}
Deadline dTask = new Deadline(taskDesc, deadline);
ls.addTask(dTask);
Expand All @@ -77,7 +77,7 @@ public static void main(String[] args) {
String taskDesc = input.replaceFirst("^event", "").split(" /")[0];
String eventTime = "";
if (input.contains("/at")) {
eventTime = input.substring(input.indexOf("/at") + 3);
eventTime = input.substring(input.indexOf("/at") + 4);
}
Event eTask = new Event(taskDesc, eventTime);
ls.addTask(eTask);
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

public class Event extends Task {

protected String at;
protected String date = "";

public Event(String description, String at) throws DukeException {
super(description);
this.at = at;

try {
LocalDate localDate = LocalDate.parse(at);
this.date = localDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy"));
} catch (DateTimeParseException e) {
throw new DukeException("Event date should be in a yyyy-mm-dd format.");
}

if (description.isEmpty() || description == "" || description == " ") {
throw new DukeException("☹ OOPS!!! The description of an event cannot be empty.");
Expand All @@ -15,7 +26,7 @@ public Event(String description, String at) throws DukeException {
if (at.isEmpty() || at == "" || at == " ") {
throw new DukeException("☹ OOPS!!! The time of the event must be indicated.");
} else {
this.at = at.substring(1);
this.at = this.date;
}
}

Expand Down

0 comments on commit e6a51b1

Please sign in to comment.