import System.Locale import Data.Time import Control.Monad import Control.Monad.Instances () import Data.List readMyTime :: String -> UTCTime readMyTime = readTime defaultTimeLocale "%F %T%Q %Z" timelogFormat :: TimeZone -> UTCTime -> String timelogFormat tz = formatTime defaultTimeLocale "%Y/%m/%d %T" . utcToLocalTime tz splitEvent :: String -> (UTCTime, [String]) splitEvent event = case words event of date : time : tz : "tags:" : tags -> (readMyTime (unwords [date, time, init tz]), tags) _ -> error ("splitEvent: " ++ event) work :: TimeZone -> [String] -> [String] work tz = concat . (zipWith f `ap` (tail . map fst)) . map splitEvent where f (a, b) c = [ unwords ["i", timelogFormat tz a, intercalate "," b] , unwords ["o", timelogFormat tz c] ] main :: IO () main = do tz <- getCurrentTimeZone interact $ unlines . work tz . lines