Skip to content

Instantly share code, notes, and snippets.

@LordNairu
Last active August 29, 2015 14:04
Show Gist options
  • Save LordNairu/eeb9c6419d5160c61c7d to your computer and use it in GitHub Desktop.
Save LordNairu/eeb9c6419d5160c61c7d to your computer and use it in GitHub Desktop.
/**
* 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