hledger/Ledger/TimeLog.hs

60 lines
1.6 KiB
Haskell
Raw Normal View History

{-|
A 'TimeLog' is a parsed timelog file (generated by timeclock.el).
It contains zero or more 'TimeLogEntry's.
-}
module Ledger.TimeLog
where
import Ledger.Utils
2008-10-03 04:12:59 +04:00
import Ledger.Types
import Ledger.Currency
import Ledger.Amount
import Ledger.RawTransaction
2008-10-03 06:37:19 +04:00
import Ledger.Entry
import Ledger.RawLedger
instance Show TimeLogEntry where
show t = printf "%s %s %s" (show $ tlcode t) (tldatetime t) (tlcomment t)
instance Show TimeLog where
show tl = printf "TimeLog with %d entries" $ length $ timelog_entries tl
2008-10-03 02:17:04 +04:00
ledgerFromTimeLog :: TimeLog -> RawLedger
ledgerFromTimeLog tl =
2008-10-03 02:17:04 +04:00
RawLedger [] [] (entriesFromTimeLogEntries $ timelog_entries tl) ""
2008-10-03 06:37:19 +04:00
entriesFromTimeLogEntries :: [TimeLogEntry] -> [Entry]
entriesFromTimeLogEntries [clockin] =
entriesFromTimeLogEntries [clockin, clockoutNowEntry]
entriesFromTimeLogEntries [clockin,clockout] =
[
2008-10-03 06:37:19 +04:00
Entry {
edate = indate,
estatus = True,
ecode = "",
edescription = accountname,
ecomment = "",
etransactions = [
RawTransaction accountname amount "",
RawTransaction "TIME" (-amount) ""
],
epreceding_comment_lines=""}
]
where
accountname = tlcomment clockin
intime = tldatetime clockin
indate = dateFrom $ tldatetime clockin
outtime = tldatetime clockout
2007-03-12 20:53:39 +03:00
amount = hours 0 -- read $ outtime - intime
entriesFromTimeLogEntries many =
(entriesFromTimeLogEntries $ take 2 many) ++
(entriesFromTimeLogEntries $ drop 2 many)
clockoutNowEntry = TimeLogEntry ' ' "" ""
dateFrom = id