I need to work with timestamp adding/subtracting given number of seconds from it. I chose time library and its UTFTime type to represent a timestamp. Now say I want to add 10 seconds to now. So far I came up with this:
now :: UTCTime
seconds = 10 :: Int
addUTCTime (secondsToNominalDiffTime seconds) now
This does not work becase seconds is Int but secondsToNominalDiffTime expects value of type Pico. (doclink)
I have no idea how to create value of pico type. I feel like I am missing something basic. Can you guys point me in a right direction?
NominalDiffTime has a Num instance that corresponds to seconds. You can use that directly. If you put an explicit time signature you can do it like this:
seconds :: NominalDiffTime
seconds = 10
In many cases the type signature isn’t even needed, e.g. 10 seconds from now:
addUTCTime 10 <$> getCurrentTime :: IO UTCTime
For converting arbitrary numbers (e.g. user input) to NominalDiffTime, you can use fromIntegral (for things like Int) or realToFrac (for things like Float).
Being new to haskell I have not thought about that. With your hint I know have this:
translateTimeFilter now (RelTimeFilter n u) = let
pastSeconds :: NominalDiffTime
pastSeconds = fromIntegral $ negate $ abs $ toSeconds n u
pastTime = addUTCTime pastSeconds now