module Util
( createFile
, toDate
, toEpoch
) where
import Control.Monad ( unless )
import Data.Time
import System.Directory ( doesFileExist )
toDate :: String -> UTCTime
toDate :: String -> UTCTime
toDate String
d = case Bool -> TimeLocale -> String -> String -> Maybe UTCTime
forall (m :: * -> *) t.
(MonadFail m, ParseTime t) =>
Bool -> TimeLocale -> String -> String -> m t
parseTimeM Bool
True TimeLocale
defaultTimeLocale String
"%F %R %Z" String
d of
Just UTCTime
x -> UTCTime
x
Maybe UTCTime
Nothing -> Day -> DiffTime -> UTCTime
UTCTime (Integer -> MonthOfYear -> MonthOfYear -> Day
fromGregorian Integer
1970 MonthOfYear
01 MonthOfYear
01) (Integer -> DiffTime
secondsToDiffTime Integer
0)
toEpoch :: UTCTime -> Integer
toEpoch :: UTCTime -> Integer
toEpoch UTCTime
d = String -> Integer
forall a. Read a => String -> a
read (String -> Integer) -> String -> Integer
forall a b. (a -> b) -> a -> b
$ TimeLocale -> String -> UTCTime -> String
forall t. FormatTime t => TimeLocale -> String -> t -> String
formatTime TimeLocale
defaultTimeLocale String
"%s" UTCTime
d
createFile :: FilePath -> IO ()
createFile :: String -> IO ()
createFile String
cfile = do
Bool
fileExists <- String -> IO Bool
doesFileExist String
cfile
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
fileExists (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ String -> String -> IO ()
writeFile String
cfile String
""