From 760befef897259223b0a348e33e5c000f1f1e902 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 15 Oct 2008 06:00:10 +0000 Subject: [PATCH] more cleanups --- Ledger/Commodity.hs | 4 +++- Ledger/Entry.hs | 4 ++-- Ledger/Parse.hs | 6 +++--- Ledger/TimeLog.hs | 16 ++++++++-------- Ledger/Utils.hs | 2 +- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Ledger/Commodity.hs b/Ledger/Commodity.hs index 242ac1493..44f45eda6 100644 --- a/Ledger/Commodity.hs +++ b/Ledger/Commodity.hs @@ -15,15 +15,17 @@ import Ledger.Types commoditytests = TestList [ ] + -- for nullamt, autoamt, etc. unknown = Commodity {symbol="",side=L,spaced=False,comma=False,precision=0,rate=1} +-- convenient amount and commodity constructors, for tests etc. + dollar = Commodity {symbol="$",side=L,spaced=False,comma=False,precision=2,rate=1} euro = Commodity {symbol="EUR",side=L,spaced=False,comma=False,precision=2,rate=0.760383} pound = Commodity {symbol="£",side=L,spaced=False,comma=False,precision=2,rate=0.512527} hour = Commodity {symbol="h",side=R,spaced=False,comma=False,precision=1,rate=100} --- | convenient amount constructors dollars = Amount dollar euros = Amount euro pounds = Amount pound diff --git a/Ledger/Entry.hs b/Ledger/Entry.hs index 9db568802..e699c2f82 100644 --- a/Ledger/Entry.hs +++ b/Ledger/Entry.hs @@ -1,7 +1,7 @@ {-| -An 'Entry' represents a normal entry in the ledger file. It normally -contains two or more 'RawTransaction's which balance. +An 'Entry' represents a regular entry in the ledger file. It contains two +or more 'RawTransaction's whose sum must be zero. -} diff --git a/Ledger/Parse.hs b/Ledger/Parse.hs index ec18fa4d0..f1ca305dc 100644 --- a/Ledger/Parse.hs +++ b/Ledger/Parse.hs @@ -332,9 +332,9 @@ amountquantity = do return (quantity, precision, comma) "commodity quantity" --- | parse the two strings of digits before and after a decimal point, if --- any. The integer part may contain commas, or either part may be empty, --- or there may be no point. +-- | parse the two strings of digits before and after a possible decimal +-- point. The integer part may contain commas, or either part may be +-- empty, or there may be no point. numberparts :: Parser (String,String) numberparts = numberpartsstartingwithdigit <|> numberpartsstartingwithpoint diff --git a/Ledger/TimeLog.hs b/Ledger/TimeLog.hs index f2beaff19..c12d227b0 100644 --- a/Ledger/TimeLog.hs +++ b/Ledger/TimeLog.hs @@ -1,7 +1,7 @@ {-| -A 'TimeLog' is a parsed timelog file (generated by timeclock.el), -containing zero or more 'TimeLogEntry's. It can be converted to a +A 'TimeLog' is a parsed timelog file (see timeclock.el or the command-line +version) containing zero or more 'TimeLogEntry's. It can be converted to a 'RawLedger' for querying. -} @@ -34,7 +34,9 @@ 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. --- "Now" would be preferable but requires IO, for now use the clockin time. +-- An entry for now is what we want but this requires IO so for now use +-- the clockin time, ie don't count the current clocked-in period. +clockoutFor :: TimeLogEntry -> TimeLogEntry clockoutFor (TimeLogEntry _ t _) = TimeLogEntry 'o' t "" -- | Convert a timelog clockin and clockout entry to an equivalent ledger @@ -52,12 +54,10 @@ entryFromTimeLogInOut i o = } where acctname = tlcomment i - indate = showDateFrom intime - outdate = showDateFrom outtime + indate = showdate intime + outdate = showdate outtime + showdate = formatTime defaultTimeLocale "%Y/%m/%d" intime = parsedatetime $ tldatetime i outtime = parsedatetime $ tldatetime o amount = hours $ realToFrac (diffUTCTime outtime intime) / 3600 txns = [RawTransaction acctname amount "", RawTransaction "assets:TIME" (-amount) ""] - -showDateFrom :: UTCTime -> String -showDateFrom = formatTime defaultTimeLocale "%Y/%m/%d" diff --git a/Ledger/Utils.hs b/Ledger/Utils.hs index 71ffc012c..9637a8714 100644 --- a/Ledger/Utils.hs +++ b/Ledger/Utils.hs @@ -1,6 +1,6 @@ {-| -Standard always-available imports and utilities. +Provide a number of standard modules and utilities. -}