Source

astrosearch / TimeUtils.hs


module TimeUtils 
       (
         readTimeString
       , timeToDbl
       )
where
  
import Data.Time (UTCTime, formatTime, readTime)
import System.Locale (defaultTimeLocale)

-- QUS: what is the better way to do the following?
  
-- | Convert a time into a Double (number of seconds since the UNIX
--   epoch.
timeToDbl :: UTCTime -> Double
timeToDbl = read . formatTime defaultTimeLocale "%s" 

-- | Convert a string to a time given a format specifier.
readTimeString :: 
  String      -- ^ Format specifier (e.g. "%b %d %T %z %Y")
  -> String   -- ^ Time
  -> UTCTime
readTimeString = readTime defaultTimeLocale