Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
whats-open-android
Commits
45d7a483
Commit
45d7a483
authored
Feb 22, 2017
by
Robert Hitt
Browse files
Fixed some more logic errors
parent
5fc5f972
Pipeline
#932
passed with stages
in 5 minutes and 20 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/srct/whatsopen/presenters/MainPresenter.java
View file @
45d7a483
...
@@ -158,25 +158,58 @@ public class MainPresenter {
...
@@ -158,25 +158,58 @@ public class MainPresenter {
OpenTimes
currentOpenTimes
=
null
;
OpenTimes
currentOpenTimes
=
null
;
for
(
OpenTimes
o
:
openTimesList
)
{
for
(
OpenTimes
o
:
openTimesList
)
{
if
(
o
.
getStartDay
()
<
=
currentDay
&&
o
.
getEndDay
()
>
=
currentDay
)
{
if
(
o
.
getStartDay
()
=
=
currentDay
&&
o
.
getEndDay
()
=
=
currentDay
)
{
currentOpenTimes
=
o
;
currentOpenTimes
=
o
;
// for some reason in the Api this signifies a facility that's open 24/7, sometimes
// for some reason in the Api this signifies a facility that's open 24/7, sometimes
// praying for that api v2
// 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"
))
{
&&
currentOpenTimes
.
getEndTime
().
equals
(
"00:00:00"
))
{
return
true
;
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
()));
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
{
try
{
Date
startTime
=
sdf
.
parse
(
currentOpenTimes
.
getStartTime
());
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
());
Date
endTime
=
sdf
.
parse
(
currentOpenTimes
.
getEndTime
());
// have to parse it from date to string to date. how fun
// have to parse it from date to string to date. how fun
Date
currentTime
=
sdf
.
parse
(
sdf
.
format
(
now
.
getTime
()));
Date
currentTime
=
sdf
.
parse
(
sdf
.
format
(
now
.
getTime
()));
if
(
currentTime
.
compareTo
(
startTime
)
>
0
&&
currentTime
.
compareTo
(
endTime
)
<
0
)
if
(
currentTime
.
compareTo
(
endTime
)
<
0
)
return
true
;
return
true
;
}
catch
(
ParseException
pe
)
{
}
catch
(
ParseException
pe
)
{
pe
.
printStackTrace
();
pe
.
printStackTrace
();
...
...
app/src/main/java/srct/whatsopen/views/activities/MainActivity.java
View file @
45d7a483
...
@@ -6,7 +6,6 @@ import android.content.Intent;
...
@@ -6,7 +6,6 @@ import android.content.Intent;
import
android.content.SharedPreferences
;
import
android.content.SharedPreferences
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.view.MenuItemCompat
;
import
android.support.v4.view.ViewPager
;
import
android.support.v4.view.ViewPager
;
import
android.support.v7.app.AppCompatActivity
;
import
android.support.v7.app.AppCompatActivity
;
import
android.support.v7.preference.PreferenceManager
;
import
android.support.v7.preference.PreferenceManager
;
...
...
app/src/test/java/srct/whatsopen/MainPresenterUnitTest.java
View file @
45d7a483
...
@@ -58,7 +58,7 @@ public class MainPresenterUnitTest {
...
@@ -58,7 +58,7 @@ public class MainPresenterUnitTest {
@Test
@Test
public
void
testFacilityIsOpenPastMidnight
()
{
public
void
testFacilityIsOpenPastMidnight
()
{
// Set date
// Set date
now
.
set
(
2017
,
0
,
12
,
1
,
0
);
// Thursday, 1/12/2017, 0
2
:00:00
now
.
set
(
2017
,
0
,
12
,
1
,
0
);
// Thursday, 1/12/2017, 0
1
:00:00
// Add more open times
// Add more open times
OpenTimes
o3
=
new
OpenTimes
(
2
,
2
,
"13:00:00"
,
"23:59:59"
);
// Wednesday 13:00-midnight
OpenTimes
o3
=
new
OpenTimes
(
2
,
2
,
"13:00:00"
,
"23:59:59"
);
// Wednesday 13:00-midnight
...
@@ -71,6 +71,32 @@ public class MainPresenterUnitTest {
...
@@ -71,6 +71,32 @@ public class MainPresenterUnitTest {
assertTrue
(
mPresenter
.
getOpenStatus
(
mFacility
,
now
));
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
@Test
public
void
testFacilityIsClosed
()
{
public
void
testFacilityIsClosed
()
{
// Set date
// Set date
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment