From 3d74656f9aa1987345d2318b94d1f2236505e373 Mon Sep 17 00:00:00 2001 From: jsabin Date: Tue, 29 May 2018 14:49:18 -0600 Subject: [PATCH] Fix for issue #71 Allow Query setTime and EndTime to be equal --- .../org/kairosdb/client/builder/TimeValidator.java | 10 +++++----- .../org/kairosdb/client/builder/TimeValidatorTest.java | 10 ++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/kairosdb/client/builder/TimeValidator.java b/src/main/java/org/kairosdb/client/builder/TimeValidator.java index 7b6cf03..1f5223b 100644 --- a/src/main/java/org/kairosdb/client/builder/TimeValidator.java +++ b/src/main/java/org/kairosdb/client/builder/TimeValidator.java @@ -22,7 +22,7 @@ */ public class TimeValidator { - private static final String START_TIME_EARLIER = "Start time must be earlier than the ending time\" (note the subtle difference"; + private static final String START_TIME_EARLIER = "Start time must be equal to or earlier than the ending time"; private TimeValidator() { @@ -30,24 +30,24 @@ private TimeValidator() public static void validateEndTimeLaterThanStartTime(long startTime, long endTime) { - checkState(endTime > startTime, START_TIME_EARLIER); + checkState(endTime >= startTime, START_TIME_EARLIER); } public static void validateEndTimeLaterThanStartTime(RelativeTime startTime, RelativeTime endTime) { long now = System.currentTimeMillis(); - checkState(startTime.getTimeRelativeTo(now) < endTime.getTimeRelativeTo(now), START_TIME_EARLIER); + checkState(startTime.getTimeRelativeTo(now) <= endTime.getTimeRelativeTo(now), START_TIME_EARLIER); } public static void validateEndTimeLaterThanStartTime(long startTime, RelativeTime endTime) { long now = System.currentTimeMillis(); - checkState(startTime < endTime.getTimeRelativeTo(now), START_TIME_EARLIER); + checkState(startTime <= endTime.getTimeRelativeTo(now), START_TIME_EARLIER); } public static void validateEndTimeLaterThanStartTime(RelativeTime startTime, long endTime) { long now = System.currentTimeMillis(); - checkState(startTime.getTimeRelativeTo(now) < endTime, START_TIME_EARLIER); + checkState(startTime.getTimeRelativeTo(now) <= endTime, START_TIME_EARLIER); } } \ No newline at end of file diff --git a/src/test/java/org/kairosdb/client/builder/TimeValidatorTest.java b/src/test/java/org/kairosdb/client/builder/TimeValidatorTest.java index d8a783c..12e911c 100644 --- a/src/test/java/org/kairosdb/client/builder/TimeValidatorTest.java +++ b/src/test/java/org/kairosdb/client/builder/TimeValidatorTest.java @@ -86,4 +86,14 @@ public void test_RelativeStartLaterThanRelativeEnd_Invalid() TimeValidator.validateEndTimeLaterThanStartTime(startTime, endTime); } + @Test + public void test_StartAndEndTimeEqual() + { + long time = System.currentTimeMillis(); + RelativeTime relativetime = new RelativeTime(2, TimeUnit.DAYS); + TimeValidator.validateEndTimeLaterThanStartTime(time, time); + TimeValidator.validateEndTimeLaterThanStartTime(new RelativeTime(1, TimeUnit.HOURS), new RelativeTime(1, TimeUnit.HOURS)); + TimeValidator.validateEndTimeLaterThanStartTime(relativetime.getTimeRelativeTo(System.currentTimeMillis()), relativetime); + TimeValidator.validateEndTimeLaterThanStartTime(relativetime, relativetime.getTimeRelativeTo(System.currentTimeMillis())); + } } \ No newline at end of file