Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c4e0537
Add date and time variables in Deadline.java
W1ndB10w Oct 2, 2025
e3bbb2f
Modify constructor in Deadline.java
W1ndB10w Oct 2, 2025
59289d8
Add parseDate method in Deadline.java
W1ndB10w Oct 2, 2025
379baf3
Modify getFullStatus method in Deadline.java
W1ndB10w Oct 2, 2025
a04353b
Add date and time getters in Deadline.java
W1ndB10w Oct 2, 2025
37ee773
Import time and date in Deadline.java
W1ndB10w Oct 2, 2025
bdd9f7a
Add date and time variables in Event.java
W1ndB10w Oct 2, 2025
18c8c28
Import time and date in Event.java
W1ndB10w Oct 2, 2025
474e7b9
Modify constructor in Event.java
W1ndB10w Oct 2, 2025
8f16114
Add parseDate method in Event.java
W1ndB10w Oct 2, 2025
69d8d3f
Modify getFullStatus method in Event.java
W1ndB10w Oct 2, 2025
c53d63b
Add date and time getters in Event.java
W1ndB10w Oct 2, 2025
0d8d87b
Update error messages in parseDeadline method in Parser.java
W1ndB10w Oct 2, 2025
5722e25
Update error messages in getEventParts method in Parser.java
W1ndB10w Oct 2, 2025
e04a77f
Import time and date in Ui.java
W1ndB10w Oct 2, 2025
bb74e10
Change date output format
W1ndB10w Oct 2, 2025
3e909de
Add showSchedule method in Ui.java
W1ndB10w Oct 2, 2025
e1d3d7b
Update showSchedule method in Ui.java
W1ndB10w Oct 2, 2025
147939e
Create ScheduleCommand Subclass
W1ndB10w Oct 2, 2025
6ee888a
Add constructor in ScheduleCommand.java
W1ndB10w Oct 2, 2025
24eddad
Add 'schedule' case in switch statement in Parser.java
W1ndB10w Oct 2, 2025
0d48c96
Override execute method in ScheduleCommand.java
W1ndB10w Oct 2, 2025
500ffb8
Update execute method in ScheduleCommand.java
W1ndB10w Oct 2, 2025
9228c26
Refactor ScheduleCommand.java
W1ndB10w Oct 2, 2025
5b9d412
Replace concatenations with text blocks in Parser.java
W1ndB10w Oct 2, 2025
440e2fb
Remove redundant getter in Deadline.java
W1ndB10w Oct 2, 2025
dd88ecb
Remove redundant getters in Event.java
W1ndB10w Oct 2, 2025
078033e
Set locale to English in Deadline.java
W1ndB10w Oct 2, 2025
4334258
Set locale to English in Event.java
W1ndB10w Oct 2, 2025
f4b6aa0
Set locale to English in Ui.java
W1ndB10w Oct 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Locale;

public class Deadline extends Task {
protected String by;
protected LocalDate byDate;
private static final DateTimeFormatter INPUT_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd");
private static final DateTimeFormatter OUTPUT_FORMAT = DateTimeFormatter.ofPattern("MMM dd yyyy", Locale.ENGLISH);

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

private LocalDate parseDate(String dateString) {
try {
return LocalDate.parse(dateString, INPUT_FORMAT);
} catch (DateTimeParseException e) {
return null;
}
}

@Override
public String getFullStatus() {
return "[D]" + super.getFullStatus() + " (by: " + by + ")";
String dateString = byDate != null ? byDate.format(OUTPUT_FORMAT) : by;
return "[D]" + super.getFullStatus() + " (by: " + dateString + ")";
}

public LocalDate getByDate() {
return byDate;
}
}
31 changes: 30 additions & 1 deletion src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Locale;

public class Event extends Task {
protected String from;
protected String to;
protected LocalDate fromDate;
protected LocalDate toDate;
private static final DateTimeFormatter INPUT_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd");
private static final DateTimeFormatter OUTPUT_FORMAT = DateTimeFormatter.ofPattern("MMM dd yyyy", Locale.ENGLISH);

public Event(String description, String from, String to) {
super(description);
this.from = from;
this.to = to;
this.fromDate = parseDate(from);
this.toDate = parseDate(to);
}

private LocalDate parseDate(String dateString) {
try {
return LocalDate.parse(dateString, INPUT_FORMAT);
} catch (DateTimeParseException e) {
return null;
}
}

@Override
public String getFullStatus() {
return "[E]" + super.getFullStatus() + " (from: " + from + " to: " + to + ")";
String fromString = fromDate != null ? fromDate.format(OUTPUT_FORMAT) : from;
String toString = toDate != null ? toDate.format(OUTPUT_FORMAT) : to;
return "[E]" + super.getFullStatus() + " (from: " + fromString + " to: " + toString + ")";
}

public LocalDate getFromDate() {
return fromDate;
}

public LocalDate getToDate() {
return toDate;
}
}
21 changes: 17 additions & 4 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static Command parse(String fullCommand) throws ReverieException {
case "event" -> new AddCommand(parseEvent(trimmedCommand));
case "delete" -> new DeleteCommand(arguments);
case "find" -> new FindCommand(arguments);
case "schedule" -> new ScheduleCommand(arguments);
default -> throw new ReverieException("I'm sorry, but I don't know what that means :-(");
};
}
Expand All @@ -39,14 +40,20 @@ private static Task parseTodo(String input) throws ReverieException {

private static Task parseDeadline(String input) throws ReverieException {
if (input.length() <= "deadline ".length()) {
throw new ReverieException("The description of a deadline cannot be empty!\nFormat: deadline <description> /by <time>");
throw new ReverieException("""
The description of a deadline cannot be empty!
Format: deadline <description> /by <time>
Date format: yyyy-MM-dd (e.g., 2019-12-02)""");
}

String content = input.replaceFirst("(?i)^deadline\\s+", "").trim();
String[] parts = content.split("\\s+/by\\s+", 2);

if (parts.length < 2) {
throw new ReverieException("Invalid deadline format!\nFormat: deadline <description> /by <time>");
throw new ReverieException("""
Invalid deadline format!
Format: deadline <description> /by <time>
Date format: yyyy-MM-dd (e.g., 2019-12-02)""");
}

String description = parts[0].trim();
Expand Down Expand Up @@ -84,14 +91,20 @@ private static Task parseEvent(String input) throws ReverieException {

private static String[] getEventParts(String input) throws ReverieException {
if (input.length() <= "event ".length()) {
throw new ReverieException("The description of an event cannot be empty!\nFormat: event <description> /from <start> /to <end>");
throw new ReverieException("""
The description of an event cannot be empty!
Format: event <description> /from <start> /to <end>
Date format: yyyy-MM-dd (e.g., 2019-12-02)""");
}

String content = input.replaceFirst("(?i)^event\\s+", "").trim();
String[] parts = content.split("\\s+/from\\s+|\\s+/to\\s+", 3);

if (parts.length < 3) {
throw new ReverieException("Invalid event format!\nFormat: event <description> /from <start> /to <end>");
throw new ReverieException("""
Invalid event format!
Format: event <description> /from <start> /to <end>
Date format: yyyy-MM-dd (e.g., 2019-12-02)""");
}
return parts;
}
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/ScheduleCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;

public class ScheduleCommand extends Command {
private final String dateString;
private static final DateTimeFormatter INPUT_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd");

public ScheduleCommand(String dateString) {
this.dateString = dateString;
}

@Override
public void execute(TaskList tasks, Ui ui, Storage storage) throws ReverieException {
if (dateString.trim().isEmpty()) {
throw new ReverieException("Please specify a date to check the schedule\n" +
"Format: schedule yyyy-MM-dd (e.g., schedule 2019-12-02)");
}

LocalDate targetDate;
try {
targetDate = LocalDate.parse(dateString.trim(), INPUT_FORMAT);
} catch (DateTimeParseException e) {
throw new ReverieException("Invalid date format! Please use yyyy-MM-dd (e.g., 2019-12-02)");
}

ArrayList<Integer> matchingIndices = getIndicesFromDate(tasks, targetDate);

ui.showSchedule(tasks, matchingIndices, targetDate);
}

private static ArrayList<Integer> getIndicesFromDate(TaskList tasks, LocalDate targetDate) {
ArrayList<Integer> matchingIndices = new ArrayList<>();
ArrayList<Task> allTasks = tasks.getAllTasks();

for (int i = 0; i < allTasks.size(); i++) {
Task task = allTasks.get(i);
if (task instanceof Deadline deadline) {
if (deadline.getByDate() != null && deadline.getByDate().equals(targetDate)) {
matchingIndices.add(i);
}
} else if (task instanceof Event event) {
if (event.getFromDate() != null && event.getToDate() != null) {
if (!targetDate.isBefore(event.getFromDate()) && !targetDate.isAfter(event.getToDate())) {
matchingIndices.add(i);
}
}
}
}
return matchingIndices;
}
}
16 changes: 16 additions & 0 deletions src/main/java/Ui.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import java.util.Scanner;
import java.util.ArrayList;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

public class Ui {
private static final String HORIZONTAL_LINE = "____________________________________________________________";
private final Scanner scanner;
private static final DateTimeFormatter OUTPUT_FORMAT = DateTimeFormatter.ofPattern("MMM dd yyyy", Locale.ENGLISH);

public Ui() {
this.scanner = new Scanner(System.in);
Expand Down Expand Up @@ -108,6 +112,18 @@ public void showFoundTasks(TaskList tasks, ArrayList<Integer> matchingIndices) t
}
}

public void showSchedule(TaskList tasks, ArrayList<Integer> matchingIndices, LocalDate date) throws ReverieException {
String formattedDate = date.format(OUTPUT_FORMAT);
if (matchingIndices.isEmpty()) {
System.out.println(" No tasks scheduled for " + formattedDate + "!");
} else {
System.out.println(" Here are the tasks scheduled for " + formattedDate + ":");
for (int index : matchingIndices) {
System.out.println(" " + (index + 1) + "." + tasks.get(index).getFullStatus());
}
}
}

public void showLoadedTasks(int count) {
if (count > 0) {
showLine();
Expand Down