forked from nusCS2113-AY1920S1/PersonalAssistant-Duke
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add academic context to chosen schedule date. (nusCS2113-AY1920S1#83)
* Add schedule command * Yellow flag handling * Add ui to show schedule * Add ViewSchedule command * Add view schedule message * Add command allowing user to view time specific tasks * Change Date states to public * Change Date states to public * Add test for ViewScheduleCommand * Add ViewScheduleCommand * Change back to private states * Change back to private states * Add test for ViewScheduleCommand * Add overload showSearchResult method * Add ViewScheduleCommand * ViewScheduleCommand displays separate events and deadlines for any given time period * ViewScheduleCommand displays separate events and deadlines for any given time period * Add getDate methods * Add getDate methods * Add ViewScheduleCommand * Add javadoc * Add javadoc * Add javadoc * Organise imports * Expand imports for checkstyle :( * Bug fix * Add abstract boolean isWithinTimeFrame * Change schedule ui * Add abstract method isWithinTimeFrame * Add abstract method isWithinTimeFrame * Add abstract method isWithinTimeFrame * Test ViewScheduleCommand * Add new abtract method isWithinTimeFrame * Add new abtract method isWithinTimeFrame * Add new abtract method isWithinTimeFrame * Add Schedule for printing time table * Add ViewScheduleCommand * Add timetable interface * Add abstract Schedule method * Add abstract Schedule method * Add abstract Schedule method * Add abstract Schedule method * Organise imports * Update with ui image, features and commands * Update * Update * Update * Update * Update * Update * Update * Update * Update * Update * Update * Update * Add javadoc and format code * Change nested loop * Add javadoc * Organise imports * Organise imports * im so technically challenged * Add test for Schedule * Add test for Schedule * Update features and commands * update link to Ui.png * test * 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 * 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 academic context to date * modify ViewScheduleCommand to accept date range * add academic context to date * 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 * 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 * update with V2.0 features * update with V2.0 features * 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 * add academic context to date * update * update * update * update * update * update * update * update * add junit tests * fix checkstyle * fix checkstyle * edit according to review * change according to requested changes
- Loading branch information
Showing
19 changed files
with
310 additions
and
78 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
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,126 @@ | ||
package duchess.model; | ||
|
||
import java.time.DayOfWeek; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.Month; | ||
import java.time.temporal.ChronoUnit; | ||
import java.time.temporal.TemporalAdjusters; | ||
|
||
public class AcademicContext { | ||
private LocalDate localDate; | ||
private LocalDate startDate; | ||
private LocalDate endDate; | ||
private String academicYear; | ||
private String academicWeek; | ||
private String semester; | ||
private static final double week = 7.0; | ||
|
||
/** | ||
* Set academic context based on given date. | ||
* | ||
* @param localDateTime date | ||
*/ | ||
public AcademicContext(LocalDateTime localDateTime) { | ||
this.localDate = localDateTime.toLocalDate(); | ||
this.startDate = localDate; | ||
this.endDate = localDate; | ||
this.semester = processSemester(); | ||
this.academicWeek = processAcademicWeek(); | ||
this.academicYear = processAcademicYear(); | ||
} | ||
|
||
/** | ||
* Returns start or end date of a semester. | ||
* | ||
* @param month Month semester starts in | ||
* @param end Start or end of semester | ||
* @return LocalDate with year corresponding to constructor parameter localDateTime | ||
*/ | ||
private LocalDate processDate(Month month, boolean end) { | ||
LocalDate temp = localDate.with(month).with(TemporalAdjusters.dayOfWeekInMonth(2, DayOfWeek.MONDAY)); | ||
if (end) { | ||
temp = temp.with(TemporalAdjusters.next(DayOfWeek.SUNDAY)).plusWeeks(16); | ||
} | ||
return temp; | ||
} | ||
|
||
private String processSemester() { | ||
LocalDate semOneStart = processDate(Month.AUGUST, false); | ||
LocalDate semOneEnd = processDate(Month.AUGUST, true); | ||
LocalDate semTwoStart = processDate(Month.JANUARY, false); | ||
LocalDate semTwoEnd = processDate(Month.JANUARY, true); | ||
boolean isSemesterOne = localDate.compareTo(semOneStart) >= 0 && localDate.compareTo(semOneEnd) <= 0; | ||
boolean isSemesterTwo = localDate.compareTo(semTwoStart) >= 0 && localDate.compareTo(semTwoEnd) <= 0; | ||
boolean isSummerBreak = localDate.isAfter(semTwoEnd) && localDate.isBefore(semOneStart); | ||
|
||
if (isSemesterOne) { | ||
this.startDate = semOneStart; | ||
return "Semester 1"; | ||
} else if (isSemesterTwo) { | ||
this.startDate = semTwoStart; | ||
return "Semester 2"; | ||
} else if (isSummerBreak) { | ||
this.endDate = semOneStart; | ||
return "Summer Break"; | ||
} | ||
if (localDate.getMonth() == Month.DECEMBER) { | ||
this.endDate = semTwoStart.plusYears(1).with(TemporalAdjusters.dayOfWeekInMonth(2, DayOfWeek.MONDAY)); | ||
} else { | ||
this.endDate = semTwoStart; | ||
} | ||
return "Winter Break"; | ||
} | ||
|
||
private String processAcademicWeek() { | ||
boolean isSchoolTerm = semester.equals("Semester 1") || semester.equals("Semester 2"); | ||
|
||
long daysBetween = ChronoUnit.DAYS.between(startDate, endDate); | ||
if (isSchoolTerm) { | ||
daysBetween++; | ||
} | ||
int currWeek = (int) Math.ceil(daysBetween / week); | ||
if (isSchoolTerm) { | ||
switch (currWeek) { | ||
case 7: | ||
return "Recess Week"; | ||
case 8: | ||
case 9: | ||
case 10: | ||
case 11: | ||
case 12: | ||
case 13: | ||
case 14: | ||
return "W" + (currWeek - 1); | ||
case 15: | ||
return "Reading Week"; | ||
case 16: | ||
case 17: | ||
return "Examinations"; | ||
default: | ||
return "W" + currWeek; | ||
} | ||
} | ||
if (currWeek == 1) { | ||
return "last week of break before a new semester starts"; | ||
} else { | ||
return currWeek + " weeks left to the next semester"; | ||
} | ||
} | ||
|
||
private String processAcademicYear() { | ||
int currYear = localDate.getYear(); | ||
boolean isFirstHalf = semester.equals("Semester 1") | ||
|| (semester.equals("Winter Break") && localDate.getMonth() == Month.DECEMBER); | ||
|
||
if (isFirstHalf) { | ||
return "AY" + currYear + "/" + (currYear + 1); | ||
} else { | ||
return "AY" + (currYear - 1) + "/" + currYear; | ||
} | ||
} | ||
|
||
public String getAcademicContext() { | ||
return academicYear + ", " + semester + ", " + academicWeek; | ||
} | ||
} |
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
Oops, something went wrong.