DomainClock implements DeviceClock { static Time_t timeSampleArrayResolution(int resolutionNsPerSample, Time_t t) { if(resolutionNsPerSample >=1000000000) { int secondsMod = resolutionNsPerSample / 1000000000; int nanosecondsMod = resolutionNsPerSample % 1000000000; t.sec -= 0 == secondsMod ? 0 : (t.sec % secondsMod); if(nanosecondsMod == 0) { t.nanosec = 0; } else { t.nanosec -= 0 == nanosecondsMod ? 0 : (t.nanosec % nanosecondsMod); } } else { t.nanosec -= 0 == resolutionNsPerSample ? 0 : (t.nanosec % resolutionNsPerSample); } return t; } DomainClock(DomainParticipant dp); static void toDDSTime(long timestamp, Time_t t); static void toDDSTime(long timestamp, ice.Time_t t); static Time_t toDDSTime(long timestamp); static void toDDSTime(Instant timestamp, Time_t t); static void toDDSTime(Instant timestamp, ice.Time_t t); static Time_t toDDSTime(Instant timestamp); static long toMilliseconds(Time_t timestamp); @Override DeviceClock.Reading instant();  }
@Test public void testTimeSampleArrayResolution() { long l0 = 1426017249228L; Time_t t0 = Time_t.from_millis(l0); Instant i0 = Instant.ofEpochMilli(l0); for(int size = 25; size<900; size=(int)(size*1.3)) { int resolutionNsPerSample = DomainClock.ensureResolutionForFrequency(DomainClock.DEFAULT_SAMPLE_ARRAY_RESOLUTION, 333, size); Time_t t1 = Time_t.from_millis(l0); t1 = DomainClock.timeSampleArrayResolution(resolutionNsPerSample, t1); System.out.println(t0.sec + "." + t0.nanosec + " @resolutionNs=" + resolutionNsPerSample + " -> " + t1.sec + "." + t1.nanosec) ; Instant i1 = DomainClock.timeSampleArrayResolution(resolutionNsPerSample, i0); Assert.assertEquals("Failed @resolutionNs=" + resolutionNsPerSample, DomainClock.toMilliseconds(t1), i1.toEpochMilli()); } }