module Test.LeanCheck.Instances.Time () where
import Data.Time
import Test.LeanCheck
binarySearchIndexes :: (Num a, Integral a) => a -> a -> [a]
binarySearchIndexes min max
| min > max = []
| max == min = [max]
| otherwise = let mid = (max - min) `div` 2 + min in
mid : (binarySearchIndexes (mid + 1) max +| binarySearchIndexes min (mid - 1))
binarySearchIndexesThen :: (Num a, Integral a) => a -> a -> [a]
binarySearchIndexesThen min max = binarySearchIndexes min max ++ ([(min-1),(min-2)..] +| [(max+1)..])
secondsInADay :: Num a => a
secondsInADay = 24*60*60-1
instance Listable Day where
list = map ModifiedJulianDay $ binarySearchIndexesThen 0 116969
instance Listable DiffTime where
tiers = mapT (\(x,y) -> fromInteger x / fromInteger y) . reset
$ tiers `suchThat` \(n,d) -> n > 0 && d > 0 && n `gcd` d == 1
instance Listable UTCTime where
tiers = cons2 UTCTime