Replies: 2 comments 2 replies
-
There's an example similar to what you described in #843. Does that work? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Yes, that's the workaround i'm currently using: final AtomicReference<ZonedDateTime> dateHolder = new AtomicReference<>(ZonedDateTime.now().plusDays(1).truncatedTo(ChronoUnit.DAYS));
final List<TimePeriod> timePeriods = IntStream.range(0, 30).mapToObj(i -> Instancio.of(TimePeriod.class)
.generate(field(TimePeriod::getBegin), g -> g.temporal().zonedDateTime().range(dateHolder.get().plusHours(8), dateHolder.getAndUpdate(d -> d.plusDays(1)).plusHours(20)))
.assign(Assign.valueOf(field(TimePeriod::getBegin)).to(field(TimePeriod::getEnd)).as((ZonedDateTime dt) -> dt.plusHours(2)))
.create()).toList(); But it creates only one TimePeriod per day. A generator for generating distinct TimePeriods would be way more flexible and i would not have to use the IntStream. BTW: My real object is a little bit more complex (Something like an appointment containing a begin and an end and some other attributes). |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to generate a list of objects with distinct time periods. I have a POJO like this:
I want to generate a list of those objects like so:
where the time periods do not overlap. I had the idea to use a custom generator, but according to the documentation, it is not possible to get hold of already generated objects to generate a time period that does not reach into already generated ones.
Any ideas?
Beta Was this translation helpful? Give feedback.
All reactions