@Test public void shouldGenerateDateInTheSameTimeZoneAsFromDate() { DateTimeZone specificTimeZone = DateTimeZone.forOffsetHours(5); DateTime from = now(specificTimeZone); DateTimeZone otherTimeZone = DateTimeZone.forOffsetHours(4); DateTime to = now().plusDays(1).withZone(otherTimeZone); Generator<DateTime> randomJodaDateTimeGenerator = new RandomJodaDateTimeGenerator(from, to); DateTime generated = randomJodaDateTimeGenerator.next(); assertThat(generated.getZone(), is(specificTimeZone)); }
@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);  }