Skip to content

Commit

Permalink
fix: the CI fails because of a specific js Date behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaechler committed Oct 17, 2024
1 parent e99284c commit 776ddb8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ import org.scalacheck.{Arbitrary, Gen}
* Created by alonsodomin on 29/08/2016.
*/
trait DateTimeTestKitBase[DateTime] {
implicit final lazy val arbitraryDateTime: Arbitrary[DateTime] = Arbitrary(for {
protected def genDateTime: Gen[DateTime] = for {
second <- Gen.choose(Seconds.min, Seconds.max)
minute <- Gen.choose(Minutes.min, Minutes.max)
hour <- Gen.choose(Hours.min, Hours.max)
year <- Gen.choose(1990, 2020)
yearMonth <- Gen.choose(Months.min, Months.max).map(YearMonth.of(year, _))
dayOfMonth <- Gen.choose(DaysOfMonth.min, yearMonth.lengthOfMonth())
} yield createDateTime(second, minute, hour, dayOfMonth, yearMonth.getMonthValue, year))
} yield createDateTime(second, minute, hour, dayOfMonth, yearMonth.getMonthValue, year)

implicit final lazy val arbitraryDateTime: Arbitrary[DateTime] = Arbitrary(genDateTime)

protected def createDateTime(
seconds: Int,
Expand Down
8 changes: 7 additions & 1 deletion tests/js/src/test/scala/cron4s/lib/js/JSDateSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@
package cron4s.lib.js

import cron4s.testkit.IsDateTimeTestKit
import org.scalacheck.Gen

import scala.scalajs.js.Date

/**
* Created by alonsodomin on 02/09/2016.
*/
class JSDateSpec extends IsDateTimeTestKit[Date]("JSDate") with JSTestBase
class JSDateSpec extends IsDateTimeTestKit[Date]("JSDate") with JSTestBase {
// js date implementation has a very specific behavior when setting month : if the day
// doesn't exist in the target month (say the 31) then setting the month to n is actually
// setting it to n+1 and it makes property tests to fail
override protected def genDateTime: Gen[Date] = super.genDateTime.suchThat(_.getDate() < 29)
}

0 comments on commit 776ddb8

Please sign in to comment.