imp:timeclock: more informative error output for clashing sessions [#2417]
This commit is contained in:
parent
539a876e7a
commit
04e6c140c0
@ -106,21 +106,28 @@ pairClockEntries (entry : rest) actives sessions
|
|||||||
(idate, odate) = (localDay itime, localDay otime)
|
(idate, odate) = (localDay itime, localDay otime)
|
||||||
omidnight = entry {tldatetime = itime {localDay = idate, localTimeOfDay = TimeOfDay 23 59 59}}
|
omidnight = entry {tldatetime = itime {localDay = idate, localTimeOfDay = TimeOfDay 23 59 59}}
|
||||||
imidnight = inentry {tldatetime = itime {localDay = addDays 1 idate, localTimeOfDay = midnight}}
|
imidnight = inentry {tldatetime = itime {localDay = addDays 1 idate, localTimeOfDay = midnight}}
|
||||||
(sessions', actives', rest') =
|
(sessions', actives', rest')
|
||||||
if odate > idate
|
| odate > idate = (Session {in' = inentry, out = omidnight} : sessions, imidnight : newactive, entry : rest)
|
||||||
then (Session {in' = inentry, out = omidnight} : sessions, imidnight : newactive, entry : rest)
|
| otherwise = (Session {in' = inentry, out = entry} : sessions, newactive, rest)
|
||||||
else (Session {in' = inentry, out = entry} : sessions, newactive, rest)
|
inentries = case filter ((== tlaccount entry) . tlaccount) actives of
|
||||||
l = show $ unPos $ sourceLine $ tlsourcepos entry
|
[] -> entry : actives
|
||||||
c = unPos $ sourceColumn $ tlsourcepos entry
|
activesinthisacct -> error' $ T.unpack $ makeTimeClockErrorExcerpt entry $ T.unlines $ [
|
||||||
inentries =
|
"Simultaneous sessions with the same account name are not supported."
|
||||||
if any (\e -> tlaccount e == tlaccount entry) actives
|
,"This clockin overlaps with:"
|
||||||
then error' $ printf
|
] <> map (flip makeTimeClockErrorExcerpt "") activesinthisacct
|
||||||
"%s:\n%s\n%s\n\nEncountered clockin entry for session \"%s\" that is already active."
|
-- XXX better to show full session(s)
|
||||||
(sourcePosPretty $ tlsourcepos entry)
|
-- <> map T.show (filter ((`elem` activesinthisacct).in') sessions)
|
||||||
(l ++ " | " ++ show entry)
|
|
||||||
(replicate (length l) ' ' ++ " |" ++ replicate c ' ' ++ "^")
|
makeTimeClockErrorExcerpt :: TimeclockEntry -> T.Text -> T.Text
|
||||||
(tlaccount entry)
|
makeTimeClockErrorExcerpt e@TimeclockEntry{tlsourcepos=pos} msg = T.unlines [
|
||||||
else entry : actives
|
T.pack (sourcePosPretty pos) <> ":"
|
||||||
|
,l <> " | " <> T.show e
|
||||||
|
-- ,T.replicate (T.length l) " " <> " |" -- <> T.replicate c " " <> "^")
|
||||||
|
,""
|
||||||
|
] <> msg
|
||||||
|
where
|
||||||
|
l = T.show $ unPos $ sourceLine $ tlsourcepos e
|
||||||
|
-- c = unPos $ sourceColumn $ tlsourcepos e
|
||||||
|
|
||||||
-- | Convert time log entries to journal transactions, allowing multiple clocked-in sessions at once.
|
-- | Convert time log entries to journal transactions, allowing multiple clocked-in sessions at once.
|
||||||
-- This is the new, default behaviour.
|
-- This is the new, default behaviour.
|
||||||
|
|||||||
@ -4804,6 +4804,9 @@ $ hledger -f t.timeclock print
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Note, you can have overlapping sessions (multiple sessions open simultaneously), but they must have different account names.
|
||||||
|
Overlapping sessions with the same account name are currently not supported currently.
|
||||||
|
|
||||||
Here is a
|
Here is a
|
||||||
[sample.timeclock](https://raw.github.com/simonmichael/hledger/master/examples/sample.timeclock) to
|
[sample.timeclock](https://raw.github.com/simonmichael/hledger/master/examples/sample.timeclock) to
|
||||||
download and some queries to try:
|
download and some queries to try:
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
$$$ hledger check -f tcorderedactions.timeclock
|
$$$ hledger check -f tcorderedactions.timeclock
|
||||||
>>>2 /Error: .*tcorderedactions.timeclock:8:1:
|
>>>2 /Error: .*tcorderedactions.timeclock:8:1:
|
||||||
8 \| i 2022-01-01 00:01:00 a
|
8 \| i 2022-01-01 00:01:00 a
|
||||||
\| \^
|
|
||||||
|
|
||||||
Encountered clockin entry for session "a" that is already active.
|
Simultaneous sessions with the same account name are not supported.
|
||||||
|
This clockin overlaps with:
|
||||||
/
|
/
|
||||||
>>>= 1
|
>>>= 1
|
||||||
|
|
||||||
|
|||||||
@ -192,6 +192,17 @@ $ hledger -f timeclock:- print
|
|||||||
|
|
||||||
>=
|
>=
|
||||||
|
|
||||||
|
# ** 14. Sessions with the same account name may not overlap (#2417).
|
||||||
|
<
|
||||||
|
i 2024-01-01 13:00:00 a
|
||||||
|
o 2024-01-01 15:00:00
|
||||||
|
i 2024-01-01 14:00:00 a
|
||||||
|
o 2024-01-01 15:00:00
|
||||||
|
|
||||||
|
$ hledger -f timeclock:- print
|
||||||
|
>2 /Simultaneous sessions with the same account name are not supported./
|
||||||
|
>=!0
|
||||||
|
|
||||||
# ** OLD:
|
# ** OLD:
|
||||||
|
|
||||||
## multi-day sessions get a new transaction for each day
|
## multi-day sessions get a new transaction for each day
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user