@Test public void shouldGenerateDateInTheSameTimeZoneAsFromDates() { Generator<DateTime> from = new Generator<DateTime>() { public int timeZoneHours = 0; @Override public DateTime next() { return now().withZone(DateTimeZone.forOffsetHours(timeZoneHours++)); } }; Generator<DateTime> to = Generators.ofInstance(now().plusDays(10)); Generator<DateTime> randomJodaDateTimeGenerator = new RandomJodaDateTimeGenerator(from, to); assertThat(randomJodaDateTimeGenerator.next().getZone(),is(DateTimeZone.forOffsetHours(0))); assertThat(randomJodaDateTimeGenerator.next().getZone(),is(DateTimeZone.forOffsetHours(1))); assertThat(randomJodaDateTimeGenerator.next().getZone(),is(DateTimeZone.forOffsetHours(2))); }
@Override public DateTime next() { DateTime fromTime = from.next(); long lowerBound = fromTime.getMillis(); long upperBound = to.next().getMillis(); long millis = random.nextLong(upperBound - lowerBound + 1) + lowerBound; return new DateTime(millis, timeZone == null ? fromTime.getZone() : timeZone); }
RandomJodaDateTimeGenerator implements Generator<DateTime> { @Override public DateTime next() { DateTime fromTime = from.next(); long lowerBound = fromTime.getMillis(); long upperBound = to.next().getMillis(); long millis = random.nextLong(upperBound - lowerBound + 1) + lowerBound; return new DateTime(millis, timeZone == null ? fromTime.getZone() : timeZone); } }
RandomJodaDateTimeGenerator implements Generator<DateTime> { @Override public DateTime next() { DateTime fromTime = from.next(); long lowerBound = fromTime.getMillis(); long upperBound = to.next().getMillis(); long millis = random.nextLong(upperBound - lowerBound + 1) + lowerBound; return new DateTime(millis, timeZone == null ? fromTime.getZone() : timeZone); } RandomJodaDateTimeGenerator();  RandomJodaDateTimeGenerator(@Nonnull DateTime from, @Nonnull DateTime to);  RandomJodaDateTimeGenerator(@Nonnull Generator<DateTime> from, @Nonnull Generator<DateTime> to); private  RandomJodaDateTimeGenerator(Generator<DateTime> from, Generator<DateTime> to, DateTimeZone timeZone); }
RandomJodaDateTimeGenerator implements Generator<DateTime> { @Override public DateTime next() { DateTime fromTime = from.next(); long lowerBound = fromTime.getMillis(); long upperBound = to.next().getMillis(); long millis = random.nextLong(upperBound - lowerBound + 1) + lowerBound; return new DateTime(millis, timeZone == null ? fromTime.getZone() : timeZone); } RandomJodaDateTimeGenerator();  RandomJodaDateTimeGenerator(@Nonnull DateTime from, @Nonnull DateTime to);  RandomJodaDateTimeGenerator(@Nonnull Generator<DateTime> from, @Nonnull Generator<DateTime> to); private  RandomJodaDateTimeGenerator(Generator<DateTime> from, Generator<DateTime> to, DateTimeZone timeZone); static Generator<DateTime> futureDates(); static Generator<DateTime> futureDates(@Nonnull DateTime to); static Generator<DateTime> pastDates(); static Generator<DateTime> pastDates(@Nonnull DateTime from); @Override DateTime next(); Generator<DateTime> withTimeZone(DateTimeZone timeZone); }
RandomJodaDateTimeGenerator implements Generator<DateTime> { @Override public DateTime next() { DateTime fromTime = from.next(); long lowerBound = fromTime.getMillis(); long upperBound = to.next().getMillis(); long millis = random.nextLong(upperBound - lowerBound + 1) + lowerBound; return new DateTime(millis, timeZone == null ? fromTime.getZone() : timeZone); } RandomJodaDateTimeGenerator();  RandomJodaDateTimeGenerator(@Nonnull DateTime from, @Nonnull DateTime to);  RandomJodaDateTimeGenerator(@Nonnull Generator<DateTime> from, @Nonnull Generator<DateTime> to); private  RandomJodaDateTimeGenerator(Generator<DateTime> from, Generator<DateTime> to, DateTimeZone timeZone); static Generator<DateTime> futureDates(); static Generator<DateTime> futureDates(@Nonnull DateTime to); static Generator<DateTime> pastDates(); static Generator<DateTime> pastDates(@Nonnull DateTime from); @Override DateTime next(); Generator<DateTime> withTimeZone(DateTimeZone timeZone);  }