Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter is failing with ZonedDateTime generator #38

Open
hghina0 opened this issue Feb 3, 2017 · 2 comments
Open

Filter is failing with ZonedDateTime generator #38

hghina0 opened this issue Feb 3, 2017 · 2 comments

Comments

@hghina0
Copy link

hghina0 commented Feb 3, 2017

genZonedDateTime has very big space for year which is preventing strict date formatting like yyyyMMdd.

year <- Gen.choose(-292278994, 292278994)

With above range below filter mostly fails

year <- Gen.choose(-292278994, 292278994) suchThat{r => r.getYear()>1970 && r.getYear()<3000}

I know the range is due to

TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
Timestamp t1 = new Timestamp(Long.MIN_VALUE);
assertEquals("292278994-08-17 07:12:55.192", t1.toString());

However, it is better if library can provide some way to constraint year range for rational generator

@noelmarkham
Copy link
Collaborator

Hi there,

Have you seen the genDateTimeWithinRange function? This should be able to constrain the year for you.

@hghina0
Copy link
Author

hghina0 commented Feb 10, 2017

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.

@noelmarkham noelmarkham added this to the Sprint 1 - v1.0 milestone Jul 19, 2017
@github-actions github-actions bot removed the 3SP label Mar 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants