model timelog entry codes precisely
This commit is contained in:
parent
fddeb23397
commit
a78f5a1f04
@ -552,7 +552,7 @@ timelogentry = do
|
||||
many1 spacenonewline
|
||||
datetime <- ledgerdatetime
|
||||
comment <- liftM2 (++) getParentAccount restofline
|
||||
return $ TimeLogEntry code datetime comment
|
||||
return $ TimeLogEntry (read [code]) datetime comment
|
||||
|
||||
|
||||
-- misc parsing
|
||||
|
||||
@ -18,6 +18,21 @@ import Ledger.LedgerTransaction
|
||||
instance Show TimeLogEntry where
|
||||
show t = printf "%s %s %s" (show $ tlcode t) (show $ tldatetime t) (tlcomment t)
|
||||
|
||||
instance Show TimeLogCode where
|
||||
show SetBalance = "b"
|
||||
show SetRequiredHours = "h"
|
||||
show In = "i"
|
||||
show Out = "o"
|
||||
show FinalOut = "O"
|
||||
|
||||
instance Read TimeLogCode where
|
||||
readsPrec _ ('b' : xs) = [(SetBalance, xs)]
|
||||
readsPrec _ ('h' : xs) = [(SetRequiredHours, xs)]
|
||||
readsPrec _ ('i' : xs) = [(In, xs)]
|
||||
readsPrec _ ('o' : xs) = [(Out, xs)]
|
||||
readsPrec _ ('O' : xs) = [(FinalOut, xs)]
|
||||
readsPrec _ _ = []
|
||||
|
||||
-- | Convert time log entries to ledger transactions. When there is no
|
||||
-- clockout, add one with the provided current time. Sessions crossing
|
||||
-- midnight are split into days to give accurate per-day totals.
|
||||
@ -27,7 +42,7 @@ entriesFromTimeLogEntries now [i]
|
||||
| odate > idate = [entryFromTimeLogInOut i o'] ++ entriesFromTimeLogEntries now [i',o]
|
||||
| otherwise = [entryFromTimeLogInOut i o]
|
||||
where
|
||||
o = TimeLogEntry 'o' end ""
|
||||
o = TimeLogEntry Out end ""
|
||||
end = if itime > now then itime else now
|
||||
(itime,otime) = (tldatetime i,tldatetime o)
|
||||
(idate,odate) = (localDay itime,localDay otime)
|
||||
|
||||
@ -42,7 +42,6 @@ data Side = L | R deriving (Eq,Show,Ord)
|
||||
|
||||
data Commodity = Commodity {
|
||||
symbol :: String, -- ^ the commodity's symbol
|
||||
|
||||
-- display preferences for amounts of this commodity
|
||||
side :: Side, -- ^ should the symbol appear on the left or the right
|
||||
spaced :: Bool, -- ^ should there be a space between symbol and quantity
|
||||
@ -59,7 +58,7 @@ data Amount = Amount {
|
||||
newtype MixedAmount = Mixed [Amount] deriving (Eq)
|
||||
|
||||
data PostingType = RegularPosting | VirtualPosting | BalancedVirtualPosting
|
||||
deriving (Eq,Show)
|
||||
deriving (Eq,Show)
|
||||
|
||||
data Posting = Posting {
|
||||
pstatus :: Bool,
|
||||
@ -89,6 +88,14 @@ data LedgerTransaction = LedgerTransaction {
|
||||
ltpreceding_comment_lines :: String
|
||||
} deriving (Eq)
|
||||
|
||||
data TimeLogCode = SetBalance | SetRequiredHours | In | Out | FinalOut deriving (Eq,Ord)
|
||||
|
||||
data TimeLogEntry = TimeLogEntry {
|
||||
tlcode :: TimeLogCode,
|
||||
tldatetime :: LocalTime,
|
||||
tlcomment :: String
|
||||
} deriving (Eq,Ord)
|
||||
|
||||
data HistoricalPrice = HistoricalPrice {
|
||||
hdate :: Day,
|
||||
hsymbol1 :: String,
|
||||
@ -106,11 +113,7 @@ data RawLedger = RawLedger {
|
||||
filepath :: FilePath
|
||||
} deriving (Eq)
|
||||
|
||||
data TimeLogEntry = TimeLogEntry {
|
||||
tlcode :: Char,
|
||||
tldatetime :: LocalTime,
|
||||
tlcomment :: String
|
||||
} deriving (Eq,Ord)
|
||||
-- compound types for efficiency
|
||||
|
||||
data Transaction = Transaction {
|
||||
tnum :: Int,
|
||||
|
||||
8
Tests.hs
8
Tests.hs
@ -460,8 +460,8 @@ tests = [
|
||||
let now = utcToLocalTime tz now'
|
||||
nowstr = showtime now
|
||||
yesterday = prevday today
|
||||
clockin t a = TimeLogEntry 'i' t a
|
||||
clockout t = TimeLogEntry 'o' t ""
|
||||
clockin t a = TimeLogEntry In t a
|
||||
clockout t = TimeLogEntry Out t ""
|
||||
mktime d s = LocalTime d $ fromMaybe midnight $ parseTime defaultTimeLocale "%H:%M:%S" s
|
||||
showtime t = formatTime defaultTimeLocale "%H:%M" t
|
||||
assertEntriesGiveStrings name es ss = assertEqual name ss (map ltdescription $ entriesFromTimeLogEntries now es)
|
||||
@ -1308,10 +1308,10 @@ ledger8_str = unlines
|
||||
]
|
||||
|
||||
timelogentry1_str = "i 2007/03/11 16:19:00 hledger\n"
|
||||
timelogentry1 = TimeLogEntry 'i' (parsedatetime "2007/03/11 16:19:00") "hledger"
|
||||
timelogentry1 = TimeLogEntry In (parsedatetime "2007/03/11 16:19:00") "hledger"
|
||||
|
||||
timelogentry2_str = "o 2007/03/11 16:30:00\n"
|
||||
timelogentry2 = TimeLogEntry 'o' (parsedatetime "2007/03/11 16:30:00") ""
|
||||
timelogentry2 = TimeLogEntry Out (parsedatetime "2007/03/11 16:30:00") ""
|
||||
|
||||
price1_str = "P 2004/05/01 XYZ $55\n"
|
||||
price1 = HistoricalPrice (parsedate "2004/05/01") "XYZ" "$" 55
|
||||
|
||||
Loading…
Reference in New Issue
Block a user