Java Code Examples for org.joda.time.Minutes#minutesBetween()

The following examples show how to use org.joda.time.Minutes#minutesBetween() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimplifiedKinesisClientTest.java    From beam with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldCountBytesWhenSingleDataPointReturned() throws Exception {
  Instant countSince = new Instant("2017-04-06T10:00:00.000Z");
  Instant countTo = new Instant("2017-04-06T11:00:00.000Z");
  Minutes periodTime = Minutes.minutesBetween(countSince, countTo);
  GetMetricStatisticsRequest metricStatisticsRequest =
      underTest.createMetricStatisticsRequest(STREAM, countSince, countTo, periodTime);
  GetMetricStatisticsResult result =
      new GetMetricStatisticsResult().withDatapoints(new Datapoint().withSum(1.0));

  when(cloudWatch.getMetricStatistics(metricStatisticsRequest)).thenReturn(result);

  long backlogBytes = underTest.getBacklogBytes(STREAM, countSince, countTo);

  assertThat(backlogBytes).isEqualTo(1L);
}
 
Example 2
Source File: SimplifiedKinesisClientTest.java    From beam with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldCountBytesWhenMultipleDataPointsReturned() throws Exception {
  Instant countSince = new Instant("2017-04-06T10:00:00.000Z");
  Instant countTo = new Instant("2017-04-06T11:00:00.000Z");
  Minutes periodTime = Minutes.minutesBetween(countSince, countTo);
  GetMetricStatisticsRequest metricStatisticsRequest =
      underTest.createMetricStatisticsRequest(STREAM, countSince, countTo, periodTime);
  GetMetricStatisticsResult result =
      new GetMetricStatisticsResult()
          .withDatapoints(
              new Datapoint().withSum(1.0),
              new Datapoint().withSum(3.0),
              new Datapoint().withSum(2.0));

  when(cloudWatch.getMetricStatistics(metricStatisticsRequest)).thenReturn(result);

  long backlogBytes = underTest.getBacklogBytes(STREAM, countSince, countTo);

  assertThat(backlogBytes).isEqualTo(6L);
}
 
Example 3
Source File: SimplifiedKinesisClientTest.java    From beam with Apache License 2.0 6 votes vote down vote up
private void shouldHandleGetBacklogBytesError(
    Exception thrownException, Class<? extends Exception> expectedExceptionClass) {
  Instant countSince = new Instant("2017-04-06T10:00:00.000Z");
  Instant countTo = new Instant("2017-04-06T11:00:00.000Z");
  Minutes periodTime = Minutes.minutesBetween(countSince, countTo);
  GetMetricStatisticsRequest metricStatisticsRequest =
      underTest.createMetricStatisticsRequest(STREAM, countSince, countTo, periodTime);

  when(cloudWatch.getMetricStatistics(metricStatisticsRequest)).thenThrow(thrownException);
  try {
    underTest.getBacklogBytes(STREAM, countSince, countTo);
    failBecauseExceptionWasNotThrown(expectedExceptionClass);
  } catch (Exception e) {
    assertThat(e).isExactlyInstanceOf(expectedExceptionClass);
  } finally {
    reset(kinesis);
  }
}
 
Example 4
Source File: CalculateDateTimeDifference.java    From levelup-java-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void difference_between_two_dates_joda () {
	
	DateTime sinceGraduation = new DateTime(1984, 6, 4, 0, 0, GregorianChronology.getInstance());
	DateTime currentDate = new DateTime(); //current date

	Days diffInDays = Days.daysBetween(sinceGraduation, currentDate);
	Hours diffInHours = Hours.hoursBetween(sinceGraduation, currentDate);
	Minutes diffInMinutes = Minutes.minutesBetween(sinceGraduation, currentDate);
	Seconds seconds = Seconds.secondsBetween(sinceGraduation, currentDate);
	
	logger.info(diffInDays.getDays());
	logger.info(diffInHours.getHours());
	logger.info(diffInMinutes.getMinutes());
	logger.info(seconds.getSeconds());
	
	assertTrue(diffInDays.getDays() >= 10697);
	assertTrue(diffInHours.getHours() >= 256747);
	assertTrue(diffInMinutes.getMinutes() >= 15404876);
	assertTrue(seconds.getSeconds() >= 924292577);

}
 
Example 5
Source File: TestDateTimeFunctionsBase.java    From presto with Apache License 2.0 4 votes vote down vote up
private static Minutes minutesBetween(ReadableInstant start, ReadableInstant end)
{
    return Minutes.minutesBetween(start, end);
}
 
Example 6
Source File: MedtronicHistoryData.java    From AndroidAPS with GNU Affero General Public License v3.0 4 votes vote down vote up
private int getOldestDateDifference(List<PumpHistoryEntry> treatments) {

        long dt = Long.MAX_VALUE;
        PumpHistoryEntry currentTreatment = null;

        if (isCollectionEmpty(treatments)) {
            return 8; // default return of 6 (5 for diif on history reading + 2 for max allowed difference) minutes
        }

        for (PumpHistoryEntry treatment : treatments) {

            if (treatment.atechDateTime < dt) {
                dt = treatment.atechDateTime;
                currentTreatment = treatment;
            }
        }

        LocalDateTime oldestEntryTime = null;

        try {

            oldestEntryTime = DateTimeUtil.toLocalDateTime(dt);
            oldestEntryTime = oldestEntryTime.minusMinutes(3);

//            if (this.pumpTime.timeDifference < 0) {
//                oldestEntryTime = oldestEntryTime.plusSeconds(this.pumpTime.timeDifference);
//            }
        } catch (Exception ex) {
            LOG.error("Problem decoding date from last record: {}" + currentTreatment);
            return 8; // default return of 6 minutes
        }

        LocalDateTime now = new LocalDateTime();

        Minutes minutes = Minutes.minutesBetween(oldestEntryTime, now);

        // returns oldest time in history, with calculated time difference between pump and phone, minus 5 minutes
        if (isLogEnabled())
            LOG.debug("Oldest entry: {}, pumpTimeDifference={}, newDt={}, currentTime={}, differenceMin={}", dt,
                    this.pumpTime.timeDifference, oldestEntryTime, now, minutes.getMinutes());

        return minutes.getMinutes();
    }
 
Example 7
Source File: MinutesBetweenDates.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@Test
public void minutes_between_two_dates_in_java_with_joda () {
	
	// start day is 1 day in the past
	DateTime startDate = new DateTime().minusDays(1);
	DateTime endDate = new DateTime();
	
	Minutes minutes = Minutes.minutesBetween(startDate, endDate);
	
	int numberOfMinutesInDay = minutes.getMinutes();
	
	assertEquals(1440, numberOfMinutesInDay);
}
 
Example 8
Source File: DateTimeUtil.java    From AndroidAPS with GNU Affero General Public License v3.0 2 votes vote down vote up
public static int getATechDateDiferenceAsMinutes(Long date1, Long date2) {

        Minutes minutes = Minutes.minutesBetween(toLocalDateTime(date1), toLocalDateTime(date2));

        return minutes.getMinutes();
    }