Skip to content

Instantly share code, notes, and snippets.

@Cutuchiqueno
Last active December 19, 2016 12:50
Show Gist options
  • Save Cutuchiqueno/1fd666394886c1aa8fdb19ec2e83fd80 to your computer and use it in GitHub Desktop.
Save Cutuchiqueno/1fd666394886c1aa8fdb19ec2e83fd80 to your computer and use it in GitHub Desktop.
haskell learning project (ongoing) - manage a timesheet in the shell
module Main (
main
) where
-- | REF für Data Time https://two-wrongs.com/haskell-time-library-tutorial
import Data.Time
import System.Directory (doesFileExist)
data Status = Start | End | Break deriving Show
data Entry = Entry Status ZonedTime deriving Show
timeSheetEntry :: Status -> IO Entry -- can I make this pointfree
timeSheetEntry st = do
nowHere <- getZonedTime
return $ Entry st nowHere
storeEntry :: Entry -> IO ()
storeEntry (Entry s t) = do
fileExist <- doesFileExist "./timesheet"
case fileExist of
True -> appendFile "timesheet" entry
False -> writeFile "timesheet" firstentry
where
entry = show s ++ "," ++ show t ++ "\n"
firstentry = "status,timestamp\n" ++ show s ++ "," ++ show t ++ "\n"
data Person = Person
{ status :: !Status
, timestamp :: ! -- Zoned time
}
instance FromNamedRecord Person where
parseNamedRecord r = Person <$> r .: "name" <*> r .: "salary"
loadCsv :: IO ()
main = do
csvData <- BL.readFile "salaries.csv"
case decodeByName csvData of
Left err -> putStrLn err
Right (_, v) -> V.forM_ v $ \ p ->
putStrLn $ name p ++ " earns " ++ show (salary p) ++ " dollars"
main :: IO ()
main = do
currentWorkDateTime <- timeSheetEntry Start
putStrLn $ "Work Point: " ++ show currentWorkDateTime
storeEntry currentWorkDateTime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment