Commit 45d7a483 authored by Robert Hitt's avatar Robert Hitt

Fixed some more logic errors

parent 5fc5f972
Pipeline #932 passed with stages
in 5 minutes and 20 seconds
......@@ -158,25 +158,58 @@ 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;
// 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")
if (currentOpenTimes.getStartTime().equals("00:00:00")
&& currentOpenTimes.getEndTime().equals("00:00:00")) {
return true;
}
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()));
if (currentTime.compareTo(startTime) > 0 && currentTime.compareTo(endTime) < 0)
return true;
} catch (ParseException pe) {
pe.printStackTrace();
return false;
}
}
else if (o.getStartDay() == currentDay && o.getEndDay() > currentDay) {
currentOpenTimes = o;
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
try {
Date startTime = sdf.parse(currentOpenTimes.getStartTime());
// 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)
return true;
} catch (ParseException pe) {
pe.printStackTrace();
return false;
}
}
else if (o.getStartDay() < currentDay && o.getEndDay() == currentDay) {
currentOpenTimes = o;
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
try {
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)
if (currentTime.compareTo(endTime) < 0)
return true;
} catch (ParseException pe) {
pe.printStackTrace();
......
......@@ -6,7 +6,6 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.MenuItemCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.preference.PreferenceManager;
......
......@@ -58,7 +58,7 @@ public class MainPresenterUnitTest {
@Test
public void testFacilityIsOpenPastMidnight() {
// Set date
now.set(2017, 0, 12, 1, 0); // Thursday, 1/12/2017, 02:00:00
now.set(2017, 0, 12, 1, 0); // Thursday, 1/12/2017, 01:00:00
// Add more open times
OpenTimes o3 = new OpenTimes(2, 2, "13:00:00", "23:59:59"); // Wednesday 13:00-midnight
......@@ -71,6 +71,32 @@ public class MainPresenterUnitTest {
assertTrue(mPresenter.getOpenStatus(mFacility, now));
}
// this tests a different way of representing that a Facility is open past Midnight.
// No, I don't know why there are multiple ways of representing that.
@Test
public void testFacilityIsOpenPastMidnight_2() {
// Set date
now.set(2017, 0, 12, 1, 0); // Thursday, 1/12/2017, 01:00:00
// Add more open times
OpenTimes o3 = new OpenTimes(2, 3, "13:00:00", "02:00:00"); // Wednesday 13:00-Thursday 2:00
mFacility.getMainSchedule().getOpenTimesList().add(o3);
assertTrue(mPresenter.getOpenStatus(mFacility, now));
}
@Test
public void testFacilityIsOpenPastMidnight_3() {
// Set date
now.set(2017, 0, 11, 14, 0); // Wednesday, 1/11/2017, 14:00:00
// Add more open times
OpenTimes o3 = new OpenTimes(2, 3, "13:00:00", "02:00:00"); // Wednesday 13:00-Thursday 2:00
mFacility.getMainSchedule().getOpenTimesList().add(o3);
assertTrue(mPresenter.getOpenStatus(mFacility, now));
}
@Test
public void testFacilityIsClosed() {
// Set date
......
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