Created
July 31, 2012 21:31
-
-
Save lamdor/3220744 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| implicit val arbitraryDate: Arbitrary[DateTime] = Arbitrary { | |
| val gmt = DateTimeZone.UTC | |
| for { | |
| year <- Gen.choose(1970, 2050) | |
| month <- Gen.choose(1, 12) | |
| day <- Gen.choose(1, 28) // TODO: there is a better way to get the number of days in a month -- see: http://www.exampledepot.com/egs/java.util/GetDaysInMonth.html | |
| hour <- Gen.choose(0, 23) | |
| minute <- Gen.choose(0, 59) | |
| second <- Gen.choose(0, 59) | |
| millis <- Gen.choose(0, 999) | |
| } yield new DateTime(year, month, day, hour, minute, second, millis, gmt) | |
| } | |
| def arbitraryDatesWithinDayRange(dayRange: Seq[Double]) = Arbitrary { | |
| for { | |
| since <- Arbitrary.arbitrary[DateTime] | |
| daysAfter <- Gen.oneOf(dayRange) | |
| } yield Pair(since, since.plusMinutes((daysAfter * 24 * 60).toInt)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment