timelog cleanups
This commit is contained in:
parent
dff086a69d
commit
ea41778948
@ -25,43 +25,40 @@ instance Show TimeLog where
|
|||||||
|
|
||||||
-- | Convert a time log to a ledger.
|
-- | Convert a time log to a ledger.
|
||||||
ledgerFromTimeLog :: TimeLog -> RawLedger
|
ledgerFromTimeLog :: TimeLog -> RawLedger
|
||||||
ledgerFromTimeLog tl =
|
ledgerFromTimeLog tl = RawLedger [] [] (entriesFromTimeLogEntries $ timelog_entries tl) ""
|
||||||
RawLedger [] [] (entriesFromTimeLogEntries $ timelog_entries tl) ""
|
|
||||||
|
|
||||||
-- | Convert time log entries to ledger entries.
|
-- | Convert time log entries to ledger entries.
|
||||||
entriesFromTimeLogEntries :: [TimeLogEntry] -> [Entry]
|
entriesFromTimeLogEntries :: [TimeLogEntry] -> [Entry]
|
||||||
|
entriesFromTimeLogEntries [] = []
|
||||||
|
entriesFromTimeLogEntries [i] = entriesFromTimeLogEntries [i, clockoutFor i]
|
||||||
|
entriesFromTimeLogEntries (i:o:rest) = [entryFromTimeLogInOut i o] ++ entriesFromTimeLogEntries rest
|
||||||
|
|
||||||
-- | When there is a trailing clockin entry, provide the missing clockout.
|
-- | When there is a trailing clockin entry, provide the missing clockout.
|
||||||
-- "Now" would be ideal but requires IO, for now we make it the same as
|
-- "Now" would be preferable but requires IO, for now use the clockin time.
|
||||||
-- clockin time.
|
clockoutFor (TimeLogEntry _ t _) = TimeLogEntry 'o' t ""
|
||||||
entriesFromTimeLogEntries [clockin@(TimeLogEntry _ t _)] =
|
|
||||||
entriesFromTimeLogEntries [clockin, (TimeLogEntry 'o' t "")]
|
|
||||||
|
|
||||||
entriesFromTimeLogEntries [clockin,clockout] =
|
-- | Convert a timelog clockin and clockout entry to an equivalent ledger
|
||||||
[
|
-- entry, representing the time expenditure.
|
||||||
|
entryFromTimeLogInOut :: TimeLogEntry -> TimeLogEntry -> Entry
|
||||||
|
entryFromTimeLogInOut i o =
|
||||||
Entry {
|
Entry {
|
||||||
edate = indate,
|
edate = indate, -- ledger uses outdate
|
||||||
estatus = True,
|
estatus = True,
|
||||||
ecode = "",
|
ecode = "",
|
||||||
edescription = accountname,
|
edescription = acctname,
|
||||||
ecomment = "",
|
ecomment = "",
|
||||||
etransactions = [
|
etransactions = txns,
|
||||||
RawTransaction accountname amount "",
|
epreceding_comment_lines=""
|
||||||
RawTransaction "assets:TIME" (-amount) ""
|
}
|
||||||
],
|
|
||||||
epreceding_comment_lines=""}
|
|
||||||
]
|
|
||||||
where
|
where
|
||||||
accountname = tlcomment clockin
|
acctname = tlcomment i
|
||||||
indate = showDateFrom intime
|
indate = showDateFrom intime
|
||||||
intime = parsedatetime $ tldatetime clockin
|
outdate = showDateFrom outtime
|
||||||
outtime = parsedatetime $ tldatetime clockout
|
intime = parsedatetime $ tldatetime i
|
||||||
hours = fromRational (toRational (diffUTCTime outtime intime) / 3600) -- whatever
|
outtime = parsedatetime $ tldatetime o
|
||||||
|
hours = fromRational (toRational (diffUTCTime outtime intime) / 3600) -- whatever..
|
||||||
amount = Amount (getcurrency "h") hours 1
|
amount = Amount (getcurrency "h") hours 1
|
||||||
|
txns = [RawTransaction acctname amount "", RawTransaction "assets:TIME" (-amount) ""]
|
||||||
entriesFromTimeLogEntries many =
|
|
||||||
(entriesFromTimeLogEntries $ take 2 many) ++
|
|
||||||
(entriesFromTimeLogEntries $ drop 2 many)
|
|
||||||
|
|
||||||
showDateFrom :: UTCTime -> String
|
showDateFrom :: UTCTime -> String
|
||||||
showDateFrom = formatTime defaultTimeLocale "%Y/%m/%d"
|
showDateFrom = formatTime defaultTimeLocale "%Y/%m/%d"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user