forked from nusCS2113-AY1920S1/PersonalAssistant-Duke
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Calendar Modify DateTime, TaskList to accomodate Calendar. Add CalendarSelectorException.
- Loading branch information
Showing
5 changed files
with
209 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package spinbox.entities; | ||
|
||
import spinbox.DateTime; | ||
import spinbox.containers.lists.TaskList; | ||
import spinbox.exceptions.CalendarSelectorException; | ||
|
||
import java.util.List; | ||
|
||
public class Calendar { | ||
private static final String MIDNIGHT = " 00:00"; | ||
private static final String BEFORE_MIDNIGHT = " 23:59"; | ||
DateTime startDate; | ||
DateTime endDate; | ||
int modifier; | ||
|
||
public Calendar(int modifier, String date) throws CalendarSelectorException { | ||
this.modifier = modifier; | ||
setDates(date); | ||
} | ||
|
||
private void setDates(String date) throws CalendarSelectorException { | ||
switch (modifier) { | ||
case 1: | ||
startDate = new DateTime(date + MIDNIGHT); | ||
endDate = new DateTime(date + BEFORE_MIDNIGHT); | ||
break; | ||
case 2: | ||
startDate = new DateTime(date + MIDNIGHT).getStartOfTheWeek(); | ||
endDate = new DateTime(date + BEFORE_MIDNIGHT).getEndOfTheWeek(); | ||
break; | ||
case 3: | ||
startDate = new DateTime(date + MIDNIGHT).getStartOfTheMonth(); | ||
endDate = new DateTime(date + BEFORE_MIDNIGHT).getEndOfTheMonth(); | ||
break; | ||
default: | ||
throw new CalendarSelectorException(); | ||
} | ||
} | ||
|
||
public List<String> tasksInCalendar(TaskList taskList) { | ||
return taskList.viewListInterval(startDate, endDate); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/spinbox/exceptions/CalendarSelectorException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package spinbox.exceptions; | ||
|
||
public class CalendarSelectorException extends SpinBoxException { | ||
private static final String ERROR_MESSAGE = "Error: Please supply 1, 2, 3 to corresponding" | ||
+ " to day, month or year for calendar selection"; | ||
|
||
public CalendarSelectorException() { | ||
super(ERROR_MESSAGE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters