From d3c286d8b768d880529e316ecfbf291cbeca9b5d Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Mon, 12 Mar 2007 00:13:53 +0000 Subject: [PATCH] beginnings of timelog parsing --- BasicTypes.hs | 3 ++- Models.hs | 6 ++++-- Parse.hs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ TODO | 8 +++++--- Tests.hs | 10 ++++++++++ 5 files changed, 72 insertions(+), 6 deletions(-) diff --git a/BasicTypes.hs b/BasicTypes.hs index a5758065e..3b88495e0 100644 --- a/BasicTypes.hs +++ b/BasicTypes.hs @@ -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: diff --git a/Models.hs b/Models.hs index a4718b761..808ca6494 100644 --- a/Models.hs +++ b/Models.hs @@ -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 diff --git a/Parse.hs b/Parse.hs index 7145dbe11..20efa0a18 100644 --- a/Parse.hs +++ b/Parse.hs @@ -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 () diff --git a/TODO b/TODO index dbae35ab5..7286dd453 100644 --- a/TODO +++ b/TODO @@ -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 diff --git a/Tests.hs b/Tests.hs index 677d696f2..720497ad1 100644 --- a/Tests.hs +++ b/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 @@ -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 ]