timedot: more org support: dates/entries can be org headlines

Org headline prefixes (stars and space at beginning of line) are ignored.
This commit is contained in:
Simon Michael 2020-02-28 01:03:27 -08:00
parent 50f8539911
commit 190233b576
3 changed files with 74 additions and 21 deletions

View File

@ -87,21 +87,26 @@ timedotfilep :: JournalParser m ParsedJournal
timedotfilep = do many timedotfileitemp timedotfilep = do many timedotfileitemp
eof eof
get get
where
timedotfileitemp :: JournalParser m () timedotfileitemp :: JournalParser m ()
timedotfileitemp = do timedotfileitemp = do
traceparse "timedotfileitemp" traceparse "timedotfileitemp"
choice [ choice [
void $ lift emptyorcommentlinep try $ void $ lift emptyorcommentlinep'
,timedotdayp >>= \ts -> modify' (addTransactions ts) ,try timedotdayp >>= \ts -> modify' (addTransactions ts)
] <?> "timedot day entry, or default year or comment line or blank line" ,lift $ skipSome anySingle >> eolof -- an initial line not beginning with a date, ignore
] <?> "timedot day entry, or default year or comment line or blank line"
addTransactions :: [Transaction] -> Journal -> Journal addTransactions :: [Transaction] -> Journal -> Journal
addTransactions ts j = foldl' (flip ($)) j (map addTransaction ts) addTransactions ts j = foldl' (flip ($)) j (map addTransaction ts)
emptyorcommentlinep' = optional orgheadingprefixp >> emptyorcommentlinep
orgheadingprefixp = skipSome (char '*') >> skipSome spacenonewline
-- | Parse timedot day entries to zero or more time transactions for that day. -- | Parse timedot day entries to zero or more time transactions for that day.
-- @ -- @
-- 2/1 -- 2020/2/1 optional day description
-- fos.haskell .... .. -- fos.haskell .... ..
-- biz.research . -- biz.research .
-- inc.client1 .... .... .... .... .... .... -- inc.client1 .... .... .... .... .... ....
@ -109,8 +114,9 @@ addTransactions ts j = foldl' (flip ($)) j (map addTransaction ts)
timedotdayp :: JournalParser m [Transaction] timedotdayp :: JournalParser m [Transaction]
timedotdayp = do timedotdayp = do
traceparse " timedotdayp" traceparse " timedotdayp"
lift $ optional orgheadingprefixp
d <- datep <* lift eolof d <- datep <* lift eolof
es <- catMaybes <$> many (const Nothing <$> try (lift emptyorcommentlinep) <|> es <- catMaybes <$> many (const Nothing <$> try (lift emptyorcommentlinep') <|>
Just <$> (notFollowedBy datep >> timedotentryp)) Just <$> (notFollowedBy datep >> timedotentryp))
return $ map (\t -> t{tdate=d}) es -- <$> many timedotentryp return $ map (\t -> t{tdate=d}) es -- <$> many timedotentryp
@ -122,7 +128,7 @@ timedotentryp :: JournalParser m Transaction
timedotentryp = do timedotentryp = do
traceparse " timedotentryp" traceparse " timedotentryp"
pos <- genericSourcePos <$> getSourcePos pos <- genericSourcePos <$> getSourcePos
lift (skipMany spacenonewline) lift $ optional $ choice [orgheadingprefixp, skipSome spacenonewline]
a <- modifiedaccountnamep a <- modifiedaccountnamep
lift (skipMany spacenonewline) lift (skipMany spacenonewline)
hours <- hours <-

View File

@ -22,15 +22,16 @@ so it could be used to represent dated quantities other than time.
In the docs below we'll assume it's time. In the docs below we'll assume it's time.
A timedot file contains a series of day entries. A timedot file contains a series of day entries.
A day entry begins with a date, and is followed by category/quantity pairs, one per line. A day entry begins with a non-indented hledger-style [simple date](journal.html#simple-dates) (see hledger_journal(5)).
Dates are hledger-style [simple dates](journal.html#simple-dates) (see hledger_journal(5)).
Categories are hledger-style account names, optionally indented. This is followed by optionally-indented timelog items for that day, one per line.
As in a hledger journal, there must be at least two spaces between the category (account name) and the quantity. Each timelog item is a note, usually a hledger:style:account:name representing a time category,
followed by two or more spaces, and a quantity.
Quantities can be written as: Quantities can be written as:
- a sequence of dots (.) representing quarter hours. - time dots: a sequence of dots (.) representing quarter hours.
Spaces may optionally be used for grouping and readability. Spaces may optionally be used for grouping.
Eg: .... .. Eg: .... ..
- an integral or decimal number, representing hours. - an integral or decimal number, representing hours.
@ -43,8 +44,21 @@ Quantities can be written as:
The following equivalencies are assumed, currently: The following equivalencies are assumed, currently:
1m = 60s, 1h = 60m, 1d = 24h, 1w = 7d, 1mo = 30d, 1y=365d. 1m = 60s, 1h = 60m, 1d = 24h, 1w = 7d, 1mo = 30d, 1y=365d.
Blank lines and lines beginning with #, ; or * are ignored. There is some flexibility allowing notes and todo lists to be kept
An example: right in the time log, if needed:
- Blank lines and lines beginning with `#` or `;` are ignored.
- Lines not ending with a double-space and quantity are parsed as
items taking no time, which will not appear in balance reports by
default. (Add -E to see them.)
- Org headline prefixes (stars followed by at least one space, at the
start of a line) are ignored, so a timedot file can also be an org
outline. Emacs org mode users can use these to add structure and
control which parts of the file are visible.
Examples:
```timedot ```timedot
# on this day, 6h was spent on client work, 1.5h on haskell FOSS work, etc. # on this day, 6h was spent on client work, 1.5h on haskell FOSS work, etc.
@ -58,8 +72,6 @@ inc:client1 .... ....
biz:research . biz:research .
``` ```
Or with numbers:
```timedot ```timedot
2016/2/3 2016/2/3
inc:client1 4 inc:client1 4
@ -67,6 +79,30 @@ fos:hledger 3
biz:research 1 biz:research 1
``` ```
```timedot
* Time log
** 2020-01-01
*** adm:time .
*** adm:finance .
```
```timedot
** 2020-02-29
*** DONE
0700 yoga
*** UNPLANNED
*** BEGUN
hom:chores
cleaning ...
water plants
outdoor - one full watering can
indoor - light watering
*** TODO
adm:planning: trip
*** LATER
```
Reporting: Reporting:
```shell ```shell

View File

@ -16,3 +16,14 @@ $ hledger -f- print
>=0 >=0
# 2. Org mode headline prefixes are ignored.
<
* 2020-01-01
** a:aa 1
$ hledger -f- print
2020-01-01 *
(a:aa) 1.00
>=0