beginnings of timelog parsing
This commit is contained in:
parent
f52edb9e31
commit
d3c286d8b7
@ -3,7 +3,8 @@ where
|
|||||||
import Utils
|
import Utils
|
||||||
|
|
||||||
|
|
||||||
type Date = String
|
type Date = String
|
||||||
|
type DateTime = String
|
||||||
|
|
||||||
-- amounts
|
-- amounts
|
||||||
{- a simple amount is a currency, quantity pair:
|
{- a simple amount is a currency, quantity pair:
|
||||||
|
|||||||
@ -2,8 +2,9 @@
|
|||||||
module Models (
|
module Models (
|
||||||
module BasicTypes,
|
module BasicTypes,
|
||||||
module AccountName,
|
module AccountName,
|
||||||
module Entry,
|
|
||||||
module Transaction,
|
module Transaction,
|
||||||
|
module Entry,
|
||||||
|
module TimeLogEntry,
|
||||||
module EntryTransaction,
|
module EntryTransaction,
|
||||||
module Ledger,
|
module Ledger,
|
||||||
module Account
|
module Account
|
||||||
@ -13,8 +14,9 @@ import qualified Data.Map as Map
|
|||||||
|
|
||||||
import BasicTypes
|
import BasicTypes
|
||||||
import AccountName
|
import AccountName
|
||||||
import Entry
|
|
||||||
import Transaction
|
import Transaction
|
||||||
|
import Entry
|
||||||
|
import TimeLogEntry
|
||||||
import EntryTransaction
|
import EntryTransaction
|
||||||
import Ledger
|
import Ledger
|
||||||
import Account
|
import Account
|
||||||
|
|||||||
51
Parse.hs
51
Parse.hs
@ -245,6 +245,57 @@ whiteSpace1 :: Parser ()
|
|||||||
whiteSpace1 = do space; whiteSpace
|
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
|
-- utils
|
||||||
|
|
||||||
parseError :: (Show a) => a -> IO ()
|
parseError :: (Show a) => a -> IO ()
|
||||||
|
|||||||
8
TODO
8
TODO
@ -1,8 +1,10 @@
|
|||||||
optimization: add CookedLedger caching txns etc.
|
|
||||||
profile again
|
|
||||||
|
|
||||||
feature: read timelog files
|
feature: read timelog files
|
||||||
timelog parser
|
timelog parser
|
||||||
|
convert timelog entries to ledger entries
|
||||||
|
read whole file
|
||||||
|
|
||||||
|
optimization: add CookedLedger caching txns etc.
|
||||||
|
profile again
|
||||||
|
|
||||||
speed
|
speed
|
||||||
profile, refactor, optimize
|
profile, refactor, optimize
|
||||||
|
|||||||
10
Tests.hs
10
Tests.hs
@ -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
|
-- utils
|
||||||
|
|
||||||
@ -303,5 +311,7 @@ props =
|
|||||||
,ledgerPatternArgs ["a","b","--","c","b"] == (["a","b"],["c","b"])
|
,ledgerPatternArgs ["a","b","--","c","b"] == (["a","b"],["c","b"])
|
||||||
,ledgerPatternArgs ["--","c"] == ([],["c"])
|
,ledgerPatternArgs ["--","c"] == ([],["c"])
|
||||||
,ledgerPatternArgs ["--"] == ([],[])
|
,ledgerPatternArgs ["--"] == ([],[])
|
||||||
|
,parse' timelogentry timelogentry1_str `parseEquals` timelogentry1
|
||||||
|
,parse' timelogentry timelogentry2_str `parseEquals` timelogentry2
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user