Merge branch 'ubilabs--rcapp--bug-3525' into ubilabs--rcapp--master

This commit is contained in:
Bennet Brunsen committed 2016-06-09 11:48:08 +02:00
commit 72ad93dfd4
13 files changed
+271 -226

No files matched your search

@@ -22,7 +22,7 @@ public class DurationTest {
TimePoint t2 = t1.plus(d);
assertEquals(123+234, t2.asMillis());
}
@Test
public void testDurationMinus() {
TimePoint t1 = new MillisecondsTimePoint(234);
@@ -1,10 +1,14 @@
package com.sap.sailing.domain.common.test;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.Calendar;
import java.util.GregorianCalendar;
import org.junit.Test;
import com.sap.sse.common.TimePoint;
@@ -54,4 +58,29 @@ public class TimePointTest {
assertFalse(t.equals("s"));
}
@Test
public void nearestFullMinute() {
Calendar cal = new GregorianCalendar();
cal.set(Calendar.MILLISECOND, 0);
cal.set(2016, 5, 15, 10, 12, 33); // 10:12:33 on June 15, 2016 in the local time zone
final TimePoint start = new MillisecondsTimePoint(cal.getTime());
cal.set(2016, 5, 15, 10, 8, 35); // 10:08:35 on June 15, 2016 in the local time zone
final TimePoint t1 = new MillisecondsTimePoint(cal.getTime());
cal.set(2016, 5, 15, 10, 8, 31); // 10:08:31 on June 15, 2016 in the local time zone
final TimePoint t2 = new MillisecondsTimePoint(cal.getTime());
cal.set(2016, 5, 15, 10, 15, 31); // 10:15:31 on June 15, 2016 in the local time zone
final TimePoint t3 = new MillisecondsTimePoint(cal.getTime());
cal.set(2016, 5, 15, 10, 15, 37); // 10:15:31 on June 15, 2016 in the local time zone
final TimePoint t4 = new MillisecondsTimePoint(cal.getTime());
assertEquals(new MillisecondsTimePoint(new GregorianCalendar(2016, 5, 15, 10, 12, 35).getTime()), start.getNearestModuloOneMinute(t1));
assertEquals(new MillisecondsTimePoint(new GregorianCalendar(2016, 5, 15, 10, 12, 31).getTime()), start.getNearestModuloOneMinute(t2));
assertEquals(new MillisecondsTimePoint(new GregorianCalendar(2016, 5, 15, 10, 12, 31).getTime()), start.getNearestModuloOneMinute(t3));
assertEquals(new MillisecondsTimePoint(new GregorianCalendar(2016, 5, 15, 10, 12, 37).getTime()), start.getNearestModuloOneMinute(t4));
// and now at least on milliseconds example
cal.set(Calendar.MILLISECOND, 123);
final TimePoint t5 = new MillisecondsTimePoint(cal.getTime());
final Calendar t5Compare = new GregorianCalendar(2016, 5, 15, 10, 12, 37);
t5Compare.set(Calendar.MILLISECOND, 123);
assertEquals(new MillisecondsTimePoint(t5Compare.getTime()), start.getNearestModuloOneMinute(t5));
}
}
@@ -4,6 +4,14 @@
<div id="mainContent">
<h4 class="articleHeadline">What's New - SAP Sailing Race Manager</h4>
<div class="innerContent">
<h5 class="articleSubheadline">June 2016</h5>
<ul class="bulletList">
<li>The start time editing screen has now a "Sync to minute" button, which replaces
the both buttons beside the countdown. This button sets the countdown to the nearest
minute and after "Set time" the new start time will be sent to the server.</li>
</ul>
<h5 class="articleSubheadline">May 2016</h5>
<ul class="bulletList">
@@ -47,4 +47,10 @@ public interface Duration extends Serializable, Comparable<Duration> {
Duration plus(long milliseconds);
Duration plus(Duration duration);
/**
* The "modulo" operation; imagine the operation implemented as this duration's milliseconds
* modulo {@code d}'s milliseconds
*/
Duration mod(Duration d);
}
@@ -32,4 +32,11 @@ public interface TimePoint extends Comparable<TimePoint>, Serializable {
boolean after(TimePoint other);
boolean before(TimePoint other);
/**
* @return a {@link TimePoint} such that when used to set the time of a calendar, the seconds and milliseconds will
* match that of {@code syncToClosestSecondsAndMillisOf} and the time difference to {@code this} time point is
* minimal. In particular, the time difference will always be less than or equal to 30s.
*/
TimePoint getNearestModuloOneMinute(TimePoint syncToClosestSecondsAndMillisOf);
}
@@ -116,4 +116,21 @@ public abstract class AbstractTimePoint implements TimePoint {
* as {@link #getDate()}.
*/
protected void cacheDate(Date date) {}
@Override
public TimePoint getNearestModuloOneMinute(final TimePoint syncToClosestSecondsAndMillisOf) {
final Duration diffModOneMinute = this.until(syncToClosestSecondsAndMillisOf).mod(Duration.ONE_MINUTE);
final Duration diffToAdd;
if (diffModOneMinute.compareTo(Duration.ONE_SECOND.times(30l)) > 0) {
diffToAdd = Duration.ONE_MINUTE.minus(diffModOneMinute).times(-1l);
} else if (diffModOneMinute.compareTo(Duration.ONE_SECOND.times(-30l)) < 0) {
diffToAdd = Duration.ONE_MINUTE.minus(diffModOneMinute.times(-1l));
} else {
diffToAdd = diffModOneMinute;
}
final TimePoint result = this.plus(diffToAdd);
assert this.until(result).abs().compareTo(Duration.ONE_SECOND.times(30)) <= 0;
assert syncToClosestSecondsAndMillisOf.asMillis() % 60000 == result.asMillis() % 60000;
return result;
}
}
@@ -117,4 +117,9 @@ public class MillisecondsDurationImpl implements Duration {
}
}
@Override
public Duration mod(Duration d) {
return new MillisecondsDurationImpl(asMillis() % d.asMillis());
}
}