Last active
August 29, 2015 14:04
-
-
Save LordNairu/eeb9c6419d5160c61c7d to your computer and use it in GitHub Desktop.
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
/** | |
* Gets the current performance based on system time. | |
* | |
* @param performanceHandler - the Performance handler to be iterated through. | |
* @return currentPerformance - the current performance | |
* @throws ParseException - throws a parse exception (placeholder) | |
*/ | |
public Performance getCurrentPerformance() throws ParseException { | |
// Initialise performance handler and add perfs to list | |
performanceHandler = new PerformanceHandler(); | |
performanceHandler.addAllPerformancesToList(); | |
// initialise a timeParser | |
TimeParser timeParser = new TimeParser(); | |
// get a formatted current system time | |
systemTime = timeParser.formatTime(timeParser.getTime()); | |
// compare each performance start and end time to the current system | |
// time | |
for (Performance performance : performanceHandler.getPerformanceList()) { | |
startTime = timeParser.parseTime(performance.getPerfStartTime()); | |
endTime = timeParser.parseTime(performance.getPerfEndTime()); | |
currentTime = timeParser.parseTime(systemTime); | |
if (currentTime.after(startTime) && currentTime.before(endTime)) { | |
// assign correct performance | |
currentPerformance = performance; | |
} | |
} | |
// return current performance | |
return currentPerformance; | |
} | |
/** | |
* Gets the appropriate performance based on | |
* a films start time. | |
* @param startTime | |
* @return | |
* @throws ParseException | |
*/ | |
public Performance getPerformanceBasedOnFilmStartTime(String filmStartTime) throws ParseException { | |
// Initialise performance handler and add perfs to list | |
performanceHandler = new PerformanceHandler(); | |
performanceHandler.addAllPerformancesToList(); | |
// initialise a timeParser | |
TimeParser timeParser = new TimeParser(); | |
// compare each performance start and end time to the current time | |
for (Performance performance : performanceHandler.getPerformanceList()) { | |
startTime = timeParser.parseTime(performance.getPerfStartTime()); | |
endTime = timeParser.parseTime(performance.getPerfEndTime()); | |
scheduledTime = timeParser.parseTime(filmStartTime); | |
if (scheduledTime.after(startTime) && scheduledTime.before(endTime) | |
|| scheduledTime.equals(startTime)) { | |
// assign correct performance | |
currentPerformance = performance; | |
} | |
} | |
// return current performance | |
return currentPerformance; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment