module Faker.DateTime where
import Control.Monad.IO.Class (liftIO)
import Data.Text
import Data.Time
import Faker
import Faker.Combinators
utc :: Fake UTCTime
utc = do
now <- liftIO getCurrentTime
utcBetween
(UTCTime
{ utctDay = (ModifiedJulianDay {toModifiedJulianDay = 0})
, utctDayTime = 0
})
now
day :: Fake Day
day = do
now <- liftIO getCurrentTime
dayBetween (ModifiedJulianDay {toModifiedJulianDay = 0}) (utctDay now)
utcBetween :: UTCTime -> UTCTime -> Fake UTCTime
utcBetween from to = do
delta <- fromRange (0 :: Double, realToFrac $ diffUTCTime to from)
return $ addUTCTime (realToFrac delta) from
dayBetween :: Day -> Day -> Fake Day
dayBetween from to = do
delta <- fromRange (0, diffDays to from)
return $ addDays delta from
dayBetweenYears :: Integer -> Integer -> Fake Day
dayBetweenYears ystart yend =
fakeEnumFromTo (fromGregorian ystart 1 1) (fromGregorian yend 12 31)
timeBetweenHours :: Int -> Int -> Fake DiffTime
timeBetweenHours hstart hend =
secondsToDiffTime <$> fromRange (fromIntegral from, fromIntegral to)
where
from = hstart * 3600
to = hend * 3599
utcBetweenYears :: Integer -> Integer -> Fake UTCTime
utcBetweenYears ystart yend =
UTCTime <$> dayBetweenYears ystart yend <*> timeBetweenHours 0 24