beginnings of timelog parsing

This commit is contained in:
Simon Michael 2007-03-12 00:13:53 +00:00
parent f52edb9e31
commit d3c286d8b7
5 changed files with 72 additions and 6 deletions

View File

@ -3,7 +3,8 @@ where
import Utils
type Date = String
type Date = String
type DateTime = String
-- amounts
{- a simple amount is a currency, quantity pair:

View File

@ -2,8 +2,9 @@
module Models (
module BasicTypes,
module AccountName,
module Entry,
module Transaction,
module Entry,
module TimeLogEntry,
module EntryTransaction,
module Ledger,
module Account
@ -13,8 +14,9 @@ import qualified Data.Map as Map
import BasicTypes
import AccountName
import Entry
import Transaction
import Entry
import TimeLogEntry
import EntryTransaction
import Ledger
import Account

View File

@ -245,6 +245,57 @@ whiteSpace1 :: Parser ()
whiteSpace1 = do space; whiteSpace
{-
timelog grammar, from timeclock.el 2.6
A timelog contains data in the form of a single entry per line.
Each entry has the form:
CODE YYYY/MM/DD HH:MM:SS [COMMENT]
CODE is one of: b, h, i, o or O. COMMENT is optional when the code is
i, o or O. The meanings of the codes are:
b Set the current time balance, or \"time debt\". Useful when
archiving old log data, when a debt must be carried forward.
The COMMENT here is the number of seconds of debt.
h Set the required working time for the given day. This must
be the first entry for that day. The COMMENT in this case is
the number of hours in this workday. Floating point amounts
are allowed.
i Clock in. The COMMENT in this case should be the name of the
project worked on.
o Clock out. COMMENT is unnecessary, but can be used to provide
a description of how the period went, for example.
O Final clock out. Whatever project was being worked on, it is
now finished. Useful for creating summary reports.
example:
i 2007/03/10 12:26:00 hledger
o 2007/03/10 17:26:02
-}
-- timelog file parsers
timelogentry :: Parser TimeLogEntry
timelogentry = do
code <- oneOf "bhioO"
many1 spacenonewline
date <- ledgerdate
time <- many $ oneOf "0123456789:"
let datetime = date ++ " " ++ time
many spacenonewline
comment <- restofline
return $ TimeLogEntry code datetime comment
-- utils
parseError :: (Show a) => a -> IO ()

8
TODO
View File

@ -1,8 +1,10 @@
optimization: add CookedLedger caching txns etc.
profile again
feature: read timelog files
timelog parser
convert timelog entries to ledger entries
read whole file
optimization: add CookedLedger caching txns etc.
profile again
speed
profile, refactor, optimize

View File

@ -224,6 +224,14 @@ ledger7 = Ledger
}
]
timelogentry1_str = "i 2007/03/11 16:19:00 hledger\n"
timelogentry2_str = "o 2007/03/11 16:30:00\n"
timelogentry1 = TimeLogEntry 'i' "2007/03/11 16:19:00" "hledger"
timelogentry2 = TimeLogEntry 'o' "2007/03/11 16:30:00" ""
-- utils
@ -303,5 +311,7 @@ props =
,ledgerPatternArgs ["a","b","--","c","b"] == (["a","b"],["c","b"])
,ledgerPatternArgs ["--","c"] == ([],["c"])
,ledgerPatternArgs ["--"] == ([],[])
,parse' timelogentry timelogentry1_str `parseEquals` timelogentry1
,parse' timelogentry timelogentry2_str `parseEquals` timelogentry2
]