mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
0eceeb5542
Preserves most inter-entry comment lines and whitespace (but not yet a comment immediately after an entry, or whitespace/comments after the last entry.) Whitespace and comment lines are stored as part of the following entry. Lines after the last entry are stored as an extra ledger file field. Inspired by Nafai on #ledger.
53 lines
1.4 KiB
Haskell
53 lines
1.4 KiB
Haskell
module TimeLog
|
|
where
|
|
import Utils
|
|
import Types
|
|
import Currency
|
|
import Amount
|
|
import LedgerTransaction
|
|
import LedgerEntry
|
|
import LedgerFile
|
|
|
|
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
|
|
|
|
ledgerFromTimeLog :: TimeLog -> LedgerFile
|
|
ledgerFromTimeLog tl =
|
|
LedgerFile [] [] (entriesFromTimeLogEntries $ timelog_entries tl) ""
|
|
|
|
entriesFromTimeLogEntries :: [TimeLogEntry] -> [LedgerEntry]
|
|
|
|
entriesFromTimeLogEntries [clockin] =
|
|
entriesFromTimeLogEntries [clockin, clockoutNowEntry]
|
|
|
|
entriesFromTimeLogEntries [clockin,clockout] =
|
|
[
|
|
LedgerEntry {
|
|
edate = indate,
|
|
estatus = True,
|
|
ecode = "",
|
|
edescription = accountname,
|
|
ecomment = "",
|
|
etransactions = [
|
|
LedgerTransaction accountname amount "",
|
|
LedgerTransaction "TIME" (-amount) ""
|
|
],
|
|
epreceding_comment_lines=""}
|
|
]
|
|
where
|
|
accountname = tlcomment clockin
|
|
intime = tldatetime clockin
|
|
indate = dateFrom $ tldatetime clockin
|
|
outtime = tldatetime clockout
|
|
amount = hours 0 -- read $ outtime - intime
|
|
|
|
entriesFromTimeLogEntries many =
|
|
(entriesFromTimeLogEntries $ take 2 many) ++
|
|
(entriesFromTimeLogEntries $ drop 2 many)
|
|
|
|
clockoutNowEntry = TimeLogEntry ' ' "" ""
|
|
dateFrom = id
|