Open hghina0 opened 7 years ago
Hi there,
Have you seen the genDateTimeWithinRange function? This should be able to constrain the year for you.
Hello,
Thanks for pointing into right direction. However I'm facing below issue with genDateTimeWithinRange and jdk8.
import java.time.ZonedDateTime
import org.scalacheck.{Gen, Prop}
import com.fortysevendeg.scalacheck.datetime.GenDateTime.genDateTimeWithinRange
import com.fortysevendeg.scalacheck.datetime.jdk8.ArbitraryJdk8.{genDuration, genZonedDateTime}
import com.fortysevendeg.scalacheck.datetime.instances.jdk8.jdk8ForDuration
import com.fortysevendeg.scalacheck.datetime.jdk8.granularity.days
val startAndEndDateTimeGen : Gen[(ZonedDateTime,ZonedDateTime)] = for {
startZonedDateTime <- genZonedDateTime
duration <- genDuration //BTW This gen should be parametrized to control future vs past date
endZonedDateTime <- genDateTimeWithinRange(startZonedDateTime,duration)
} yield (startZonedDateTime, endZonedDateTime)
Prop.forAll(startAndEndDateTimeGen) { case (start,end ) => true }.check
! Exception raised on property evaluation.
> Exception: java.lang.ArithmeticException: long overflow
java.lang.Math.multiplyExact(Math.java:892)
Please advise.
genZonedDateTime has very big space for year which is preventing strict date formatting like yyyyMMdd.
With above range below filter mostly fails
I know the range is due to
However, it is better if library can provide some way to constraint year range for rational generator