Skip to content

Commit

Permalink
Add week view for ViewScheduleCommand (nusCS2113-AY1920S1#55)
Browse files Browse the repository at this point in the history
* test

* test

* test

* test

* test

* test

* test

* image

* image

* image

* image

* update

* update

* update

* update

* update

* update

* refactor Schedule to TimeFrame

* Add implements Comparable<TimeFrame>

* 092919 ui fix (nusCS2113-AY1920S1#2)

* udate

* udate

* refactor Schedule to TimeFrame

* update

* update

* update change in schedule command

* fix merge conflict and bug

* minor code change

* add academic context to date

* modify ViewScheduleCommand to accept date range

* add academic context to date

* update to latest (nusCS2113-AY1920S1#5)

* merge to latest (nusCS2113-AY1920S1#3)

* refactor Schedule to TimeFrame

* Add implements Comparable<TimeFrame>

* 092919 ui fix (nusCS2113-AY1920S1#2)

* udate

* udate

* refactor Schedule to TimeFrame

* Refactor Schedule class to TimeFrame  (nusCS2113-AY1920S1#40)

* Refactor TimeFrame class (nusCS2113-AY1920S1#42)

* Reimplement TimeFrameClass

* Refactor ViewScheduleCommand

* Allow for instantaneous tasks

* Implement printing of schedule

* update

* update

* update change in schedule command

* fix merge conflict and bug

* minor code change

* Add date context (nusCS2113-AY1920S1#4)

* refactor Schedule to TimeFrame

* Add implements Comparable<TimeFrame>

* 092919 ui fix (nusCS2113-AY1920S1#2)

* udate

* udate

* refactor Schedule to TimeFrame

* Refactor Schedule class to TimeFrame  (nusCS2113-AY1920S1#40)

* Refactor TimeFrame class (nusCS2113-AY1920S1#42)

* Reimplement TimeFrameClass

* Refactor ViewScheduleCommand

* Allow for instantaneous tasks

* Implement printing of schedule

* update

* update

* update change in schedule command

* fix merge conflict and bug

* minor code change

* add academic context to date

* modify ViewScheduleCommand to accept date range

* add academic context to date

* add week view

* improve code quality

* refactor Date to LocalDateTime, fix bug causing incorrect date resets

* Add week view

* Update javadoc

* remove time run

* remove time run

* Merge branch 'master' of https://github.com/AY1920S1-CS2113T-T09-2/main into add_weekView

# Conflicts:
#	src/main/java/Duke.java
#	src/main/java/duchess/logic/commands/ViewScheduleCommand.java

* fix checkstyle indentation
  • Loading branch information
limsiying authored Oct 4, 2019
1 parent a48c1fc commit 189169e
Show file tree
Hide file tree
Showing 19 changed files with 71 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ data.json
/data.json
text_file

/data.json
13 changes: 10 additions & 3 deletions data.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
[ "duchess.storage.Store", {
"taskList" : [ "java.util.ArrayList", [ [ "duchess.model.task.Todo", {
"description" : "work"
[
"duchess.storage.Store",
{
"taskList": [
"java.util.ArrayList",
[
[
"duchess.model.task.Todo",
{
"description": "work"
2 changes: 1 addition & 1 deletion src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import duchess.logic.commands.Command;
import duchess.logic.commands.exceptions.DukeException;
import duchess.logic.parser.Parser;
import duchess.model.task.DuchessLog;
import duchess.storage.Storage;
import duchess.storage.Store;
import duchess.ui.Ui;
import duchess.logic.commands.exceptions.DukeException;

public class Duke {

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/duchess/logic/commands/AddDeadlineCommand.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package duchess.logic.commands;

import duchess.storage.Storage;
import duchess.model.task.Task;
import duchess.model.task.Deadline;
import duchess.logic.commands.exceptions.DukeException;
import duchess.model.task.Deadline;
import duchess.model.task.Task;
import duchess.storage.Storage;
import duchess.storage.Store;
import duchess.ui.Ui;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duchess/logic/commands/AddEventCommand.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package duchess.logic.commands;

import duchess.storage.Storage;
import duchess.logic.commands.exceptions.DukeException;
import duchess.model.task.Event;
import duchess.storage.Storage;
import duchess.storage.Store;
import duchess.ui.Ui;

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/duchess/logic/commands/AddTodoCommand.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package duchess.logic.commands;

import duchess.storage.Storage;
import duchess.model.task.Todo;
import duchess.model.task.Task;
import duchess.logic.commands.exceptions.DukeException;
import duchess.model.task.Task;
import duchess.model.task.Todo;
import duchess.storage.Storage;
import duchess.storage.Store;
import duchess.ui.Ui;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duchess/logic/commands/ByeCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package duchess.logic.commands;

import duchess.storage.Storage;
import duchess.logic.commands.exceptions.DukeException;
import duchess.storage.Storage;
import duchess.storage.Store;
import duchess.ui.Ui;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duchess/logic/commands/Command.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package duchess.logic.commands;

import duchess.storage.Storage;
import duchess.logic.commands.exceptions.DukeException;
import duchess.storage.Storage;
import duchess.storage.Store;
import duchess.ui.Ui;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/duchess/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package duchess.logic.commands;

import duchess.storage.Storage;
import duchess.model.task.Task;
import duchess.logic.commands.exceptions.DukeException;
import duchess.model.task.Task;
import duchess.storage.Storage;
import duchess.storage.Store;
import duchess.ui.Ui;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duchess/logic/commands/DoneCommand.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package duchess.logic.commands;

import duchess.storage.Storage;
import duchess.logic.commands.exceptions.DukeException;
import duchess.model.task.Task;
import duchess.storage.Storage;
import duchess.storage.Store;
import duchess.ui.Ui;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/duchess/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package duchess.logic.commands;

import duchess.storage.Storage;
import duchess.model.task.Task;
import duchess.logic.commands.exceptions.DukeException;
import duchess.model.task.Task;
import duchess.storage.Storage;
import duchess.storage.Store;
import duchess.ui.Ui;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duchess/logic/commands/ListCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package duchess.logic.commands;

import duchess.storage.Storage;
import duchess.logic.commands.exceptions.DukeException;
import duchess.storage.Storage;
import duchess.storage.Store;
import duchess.ui.Ui;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duchess/logic/commands/SnoozeCommand.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package duchess.logic.commands;

import duchess.storage.Storage;
import duchess.logic.commands.exceptions.DukeException;
import duchess.model.task.Task;
import duchess.storage.Storage;
import duchess.storage.Store;
import duchess.ui.Ui;

Expand Down
54 changes: 39 additions & 15 deletions src/main/java/duchess/logic/commands/ViewScheduleCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
import duchess.storage.Store;
import duchess.ui.Ui;

import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.format.ResolverStyle;
import java.time.temporal.TemporalAdjusters;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class ViewScheduleCommand extends Command {
private List<String> words;
private String date;
private String view;
private TimeFrame timeFrame;

/**
Expand All @@ -27,32 +31,52 @@ public class ViewScheduleCommand extends Command {
*/
public ViewScheduleCommand(List<String> words) throws DukeException {
this.words = words;

this.date = processString("/for");
this.view = processString("view");
if (!view.equals("day") && !view.equals("week")) {
throw new DukeException("Invalid view. Please choose either day or week view.");
}
LocalDateTime start = processDate(" 0000");
LocalDateTime end = processDate(" 2359");
this.timeFrame = new TimeFrame(start, end);
}

private String processString(String keyword) throws DukeException {
int index = words.indexOf(keyword);
if (index == -1) {
throw new DukeException("Format for viewing schedule: schedule /for <date> view <view>");
}
return words.get(index + 1);
}

/**
* Creates LocalDateTime object from string input in dd/MM/yyyy HHmm.
* Process date by setting time of LocalDateTime to either 0000 or 2359.
* Also sets LocalDateTime to nearest previous or same Monday date/ nearest
* next or same Friday date if user desires week view.
*
* @return The LocalDateTime instance
* @throws DukeException Exception thrown for invalid or missing date time
* @param time either " 0000" or " 2359" to indicate timeframe
* @return the LocalDateTime instance
* @throws DukeException Thrown for invalid or missing date time and command format
*/
private LocalDateTime processDate(String time) throws DukeException {
try {
int index = words.indexOf("/for");
if (index == -1) {
throw new DukeException("Format for viewing schedule: schedule /for <date>");
}
String dateString = words.get(index + 1) + time;
boolean isWeek = view.equals("week");
boolean isStartOfDay = time.equals(" 0000");
boolean isStartOfWeek = isWeek && isStartOfDay;
boolean isEndOfWeek = isWeek && !isStartOfDay;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/uuuu HHmm")
.withResolverStyle(ResolverStyle.STRICT);
return LocalDateTime.parse(dateString, formatter);
LocalDateTime localDateTime = LocalDateTime.parse(date + time, formatter);
if (isStartOfWeek) {
localDateTime = localDateTime.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
} else if (isEndOfWeek) {
localDateTime = localDateTime.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
}
return localDateTime;
} catch (DateTimeParseException e) {
throw new DukeException("Invalid datetime. Correct format: dd/mm/yyyy hhmm");
throw new DukeException("Invalid date format. Please follow dd/MM/yyyy.");
} catch (IndexOutOfBoundsException e) {
throw new DukeException("Format for viewing schedule: schedule /for <date>");
throw new DukeException("Format for viewing schedule: schedule /for <date> view <view>");
}
}

Expand All @@ -62,12 +86,12 @@ public void execute(Store store, Ui ui, Storage storage) throws DukeException {
store.getTaskList().stream()
.filter(task -> task.getTimeFrame().fallsWithin(this.timeFrame))
.collect(Collectors.toList());

if (tasksForToday.size() <= 0) {
throw new DukeException("There are no tasks in the schedule.");
} else if (view.equals("week")) {
date = "the week with " + date;
}

Collections.sort(tasksForToday);
ui.showScheduleResult(tasksForToday, words.get(words.indexOf("/for") + 1));
ui.showScheduleResult(tasksForToday, date);
}
}
2 changes: 0 additions & 2 deletions src/main/java/duchess/model/task/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import duchess.model.Module;
import duchess.model.TimeFrame;


import java.util.List;
import java.util.Optional;

public abstract class Task implements Comparable<Task> {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/duchess/model/task/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonSetter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/duchess/storage/Storage.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package duchess.storage;

import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import duchess.logic.commands.exceptions.DukeException;
import duchess.model.task.TaskList;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/duchess/ui/Ui.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

package duchess.ui;

import duchess.logic.commands.Command;
import duchess.model.task.Task;

import java.util.List;
Expand Down Expand Up @@ -95,9 +94,8 @@ public void showSearchResult(List<Task> tasks) {
/**
* Displays schedule of a single day to user.
* Informs user if there are ongoing events.
*
* @param tasks List of tasks to show
* @param date Date of choice
* @param date Date
*/
public void showScheduleResult(List<Task> tasks, String date) {
printIndented("Here is your schedule for " + date + ":");
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/ReminderCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import duchess.logic.commands.AddDeadlineCommand;
import duchess.logic.commands.ReminderCommand;
import duchess.logic.commands.exceptions.DukeException;
import duchess.logic.parser.Parser;
import duchess.model.task.DuchessLog;
import duchess.model.task.TaskList;
import duchess.storage.Storage;
import duchess.storage.Store;
import duchess.ui.Ui;
import duchess.logic.commands.exceptions.DukeException;
import duchess.model.task.TaskList;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
Expand Down

0 comments on commit 189169e

Please sign in to comment.