forked from upstream-mirrors/OpenTracks
Bugfix: announcements should consider hours when computing minutes.
Fixes #674.
This commit is contained in:
@@ -28,8 +28,8 @@ public class AnnouncementUtilsTest {
|
|||||||
public void getAnnouncement_metric() {
|
public void getAnnouncement_metric() {
|
||||||
TrackStatistics stats = new TrackStatistics();
|
TrackStatistics stats = new TrackStatistics();
|
||||||
stats.setTotalDistance(20000);
|
stats.setTotalDistance(20000);
|
||||||
stats.setTotalTime(Duration.ofMillis(600000));
|
stats.setTotalTime(Duration.ofHours(2).plusMinutes(5).plusSeconds(10));
|
||||||
stats.setMovingTime(Duration.ofMillis(300000));
|
stats.setMovingTime(Duration.ofHours(1).plusMinutes(5).plusSeconds(10));
|
||||||
stats.setMaxSpeed(100);
|
stats.setMaxSpeed(100);
|
||||||
stats.setTotalElevationGain(6000f);
|
stats.setTotalElevationGain(6000f);
|
||||||
|
|
||||||
@@ -37,15 +37,15 @@ public class AnnouncementUtilsTest {
|
|||||||
String announcement = AnnouncementUtils.getAnnouncement(context, stats, true, true, null);
|
String announcement = AnnouncementUtils.getAnnouncement(context, stats, true, true, null);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals("OpenTracks total distance 20.00 kilometers in 5 minutes 0 seconds at 240.0 kilometers per hour", announcement);
|
assertEquals("OpenTracks total distance 20.00 kilometers in 1 hour 5 minutes 10 seconds at 18.4 kilometers per hour", announcement);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAnnouncement_withInterval_metric() {
|
public void getAnnouncement_withInterval_metric() {
|
||||||
TrackStatistics stats = new TrackStatistics();
|
TrackStatistics stats = new TrackStatistics();
|
||||||
stats.setTotalDistance(20000);
|
stats.setTotalDistance(20000);
|
||||||
stats.setTotalTime(Duration.ofMillis(600000));
|
stats.setTotalTime(Duration.ofHours(2).plusMinutes(5).plusSeconds(10));
|
||||||
stats.setMovingTime(Duration.ofMillis(300000));
|
stats.setMovingTime(Duration.ofHours(1).plusMinutes(5).plusSeconds(10));
|
||||||
stats.setMaxSpeed(100);
|
stats.setMaxSpeed(100);
|
||||||
stats.setTotalElevationGain(6000f);
|
stats.setTotalElevationGain(6000f);
|
||||||
|
|
||||||
@@ -53,12 +53,10 @@ public class AnnouncementUtilsTest {
|
|||||||
IntervalStatistics intervalStatistics = new IntervalStatistics(trackPoints, 1000);
|
IntervalStatistics intervalStatistics = new IntervalStatistics(trackPoints, 1000);
|
||||||
IntervalStatistics.Interval lastInterval = intervalStatistics.getIntervalList().get(intervalStatistics.getIntervalList().size() - 1);
|
IntervalStatistics.Interval lastInterval = intervalStatistics.getIntervalList().get(intervalStatistics.getIntervalList().size() - 1);
|
||||||
|
|
||||||
String expected = "OpenTracks total distance 20.00 kilometers in 5 minutes 0 seconds at 240.0 kilometers per hour Lap speed of 51.2 kilometers per hour";
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String announcement = AnnouncementUtils.getAnnouncement(context, stats, true, true, lastInterval);
|
String announcement = AnnouncementUtils.getAnnouncement(context, stats, true, true, lastInterval);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(expected, announcement);
|
assertEquals("OpenTracks total distance 20.00 kilometers in 1 hour 5 minutes 10 seconds at 18.4 kilometers per hour Lap speed of 51.2 kilometers per hour", announcement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,8 +63,8 @@ public class AnnouncementUtils {
|
|||||||
private static String getAnnounceTime(Context context, Duration duration) {
|
private static String getAnnounceTime(Context context, Duration duration) {
|
||||||
String result = "";
|
String result = "";
|
||||||
|
|
||||||
int hours = (int) (duration.getSeconds() / (60 * 60));
|
int hours = (int) (duration.toHours());
|
||||||
int minutes = (int) (duration.getSeconds() / 60);
|
int minutes = (int) (duration.toMinutes() % 60);
|
||||||
int seconds = (int) (duration.getSeconds() % 60);
|
int seconds = (int) (duration.getSeconds() % 60);
|
||||||
|
|
||||||
if (hours != 0) {
|
if (hours != 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user