Commit 10918167 authored by Robert Hitt's avatar Robert Hitt

Facilities open past midnight work properly now

- Also, notifications shouldn't be set for facilities open 24/7
and they should work better for facilities open past midnight
parent 094abe19
Pipeline #877 passed with stages
in 5 minutes and 4 seconds
......@@ -158,36 +158,34 @@ public class MainPresenter {
OpenTimes currentOpenTimes = null;
for(OpenTimes o : openTimesList) {
if(o.getStartDay() <= currentDay && o.getEndDay() >= currentDay)
if(o.getStartDay() <= currentDay && o.getEndDay() >= currentDay) {
currentOpenTimes = o;
}
if(currentOpenTimes == null)
return false;
// for some reason in the Api this signifies a facility that's open 24/7, sometimes
// praying for that api v2
if(currentOpenTimes.getStartTime().equals("00:00:00")
&& currentOpenTimes.getEndTime().equals("00:00:00")) {
return true;
}
// for some reason in the Api this signifies a facility that's open 24/7, sometimes
// praying for that api v2
if(currentOpenTimes.getStartTime().equals("00:00:00")
&& currentOpenTimes.getEndTime().equals("00:00:00")) {
return true;
}
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
try {
Date startTime = sdf.parse(currentOpenTimes.getStartTime());
Date endTime = sdf.parse(currentOpenTimes.getEndTime());
// have to parse it from date to string to date. how fun
Date currentTime = sdf.parse(sdf.format(now.getTime()));
try {
Date startTime = sdf.parse(currentOpenTimes.getStartTime());
Date endTime = sdf.parse(currentOpenTimes.getEndTime());
// have to parse it from date to string to date. how fun
Date currentTime = sdf.parse(sdf.format(now.getTime()));
if(currentTime.compareTo(startTime) > 0 && currentTime.compareTo(endTime) < 0)
return true;
else
return false;
} catch (ParseException pe) {
pe.printStackTrace();
return false;
if(currentTime.compareTo(startTime) > 0 && currentTime.compareTo(endTime) < 0)
return true;
} catch (ParseException pe) {
pe.printStackTrace();
return false;
}
}
}
return false;
}
// Finds the next time the facility closes or opens and returns it
......
......@@ -190,6 +190,14 @@ public class NotificationPresenter {
private static void setAlarm(Context context, String name, int day, String type,
int intervalMin, String time, String message) {
// NOTE: this doesn't set notifications based on the assumption that
// facilities shouldn't open or close at those times, thus those must indicate
// that the facility is open 24/7 or open past midnight
// As of writing this (2/9/17) there is no better way (due to the way the Api is written)
// If you're reading this and there now is an approach, please fix this
if(time.equals("00:00:00") || time.equals("23:59:59"))
return;
Long alarmTime = parseTimeStringToMs(time, day, Calendar.getInstance());
int interval = intervalMin * 60000; // parse minutes to ms
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment