dev:timeclock: cleanups
This commit is contained in:
parent
94f6f6a9a2
commit
c48c41bcd2
@ -59,7 +59,7 @@ data Sessions = Sessions
|
|||||||
active :: [TimeclockEntry]
|
active :: [TimeclockEntry]
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Find the relevant clockin in the actives list that should be paired with this clockout.
|
-- | Find the relevant clockin in the actives list that should be paired with this clockout.
|
||||||
-- If there is a session that has the same account name, then use that.
|
-- If there is a session that has the same account name, then use that.
|
||||||
-- Otherwise, if there is an active anonymous session, use that.
|
-- Otherwise, if there is an active anonymous session, use that.
|
||||||
-- Otherwise, raise an error.
|
-- Otherwise, raise an error.
|
||||||
@ -81,11 +81,11 @@ findInForOut o ([], activeins) =
|
|||||||
(l ++ " | " ++ show o)
|
(l ++ " | " ++ show o)
|
||||||
(replicate (length l) ' ' ++ " |" ++ replicate c ' ' ++ "^")
|
(replicate (length l) ' ' ++ " |" ++ replicate c ' ' ++ "^")
|
||||||
|
|
||||||
-- Assuming that entries has been sorted, we go through each time log entry.
|
-- | Assuming that entries have been sorted, we go through each time log entry.
|
||||||
-- We collect all of the "i" in the list "actives," and each time we encounter
|
-- We collect all of the "i" in the list "actives," and each time we encounter
|
||||||
-- an "o," we look for the corresponding "i" in actives.
|
-- an "o," we look for the corresponding "i" in actives.
|
||||||
-- If we cannot find it, then it is an error (since the list is sorted).
|
-- If we cannot find it, then it is an error (since the list is sorted).
|
||||||
-- If the "o" is recorded on a different day than the "i," then we close the
|
-- If the "o" is recorded on a different day than the "i" then we close the
|
||||||
-- active entry at the end of its day, replace it in the active list
|
-- active entry at the end of its day, replace it in the active list
|
||||||
-- with a start at midnight on the next day, and try again.
|
-- with a start at midnight on the next day, and try again.
|
||||||
-- This raises an error if any outs cannot be paired with an in.
|
-- This raises an error if any outs cannot be paired with an in.
|
||||||
@ -118,10 +118,11 @@ pairClockEntries (entry : rest) actives sessions
|
|||||||
(tlaccount entry)
|
(tlaccount entry)
|
||||||
else entry : actives
|
else entry : actives
|
||||||
|
|
||||||
-- | Convert time log entries to journal transactions. When there is no
|
-- | Convert time log entries to journal transactions, allowing multiple clocked-in sessions at once.
|
||||||
-- clockout, add one with the provided current time. Sessions crossing
|
-- When there is no clockout, one is added with the provided current time.
|
||||||
-- midnight are split into days to give accurate per-day totals.
|
-- Sessions crossing midnight are split into days to give accurate per-day totals.
|
||||||
-- If any entries cannot be paired as expected, then an error is raised.
|
-- If any entries cannot be paired as expected, an error is raised.
|
||||||
|
-- This is the default behaviour.
|
||||||
timeclockEntriesToTransactions :: LocalTime -> [TimeclockEntry] -> [Transaction]
|
timeclockEntriesToTransactions :: LocalTime -> [TimeclockEntry] -> [Transaction]
|
||||||
timeclockEntriesToTransactions now entries = transactions
|
timeclockEntriesToTransactions now entries = transactions
|
||||||
where
|
where
|
||||||
@ -134,9 +135,12 @@ timeclockEntriesToTransactions now entries = transactions
|
|||||||
stillopen = pairClockEntries ((active sessions) <> outs) [] []
|
stillopen = pairClockEntries ((active sessions) <> outs) [] []
|
||||||
transactions = map transactionsFromSession $ sortBy (\s1 s2 -> compare (in' s1) (in' s2)) (completed sessions ++ completed stillopen)
|
transactions = map transactionsFromSession $ sortBy (\s1 s2 -> compare (in' s1) (in' s2)) (completed sessions ++ completed stillopen)
|
||||||
|
|
||||||
-- | Convert time log entries to journal transactions, expecting the entries to be
|
-- | Convert time log entries to journal transactions, allowing only one clocked-in session at a time.
|
||||||
-- a strict in/out cycle. When there is no clockout, add one with the provided current time.
|
-- Entries must be a strict alternation of in and out, beginning with in.
|
||||||
|
-- When there is no clockout, one is added with the provided current time.
|
||||||
-- Sessions crossing midnight are split into days to give accurate per-day totals.
|
-- Sessions crossing midnight are split into days to give accurate per-day totals.
|
||||||
|
-- If entries are not in the expected in/out order, an error is raised.
|
||||||
|
-- This is the legacy behaviour, enabled by --old-timeclock.
|
||||||
timeclockEntriesToTransactionsSingle :: LocalTime -> [TimeclockEntry] -> [Transaction]
|
timeclockEntriesToTransactionsSingle :: LocalTime -> [TimeclockEntry] -> [Transaction]
|
||||||
timeclockEntriesToTransactionsSingle _ [] = []
|
timeclockEntriesToTransactionsSingle _ [] = []
|
||||||
timeclockEntriesToTransactionsSingle now [i]
|
timeclockEntriesToTransactionsSingle now [i]
|
||||||
|
|||||||
@ -106,13 +106,13 @@ timeclockfilep iopts = do many timeclockitemp
|
|||||||
-- but it simplifies code above.
|
-- but it simplifies code above.
|
||||||
now <- liftIO getCurrentLocalTime
|
now <- liftIO getCurrentLocalTime
|
||||||
-- journalFinalise expects the transactions in reverse order, so reverse the output in either case
|
-- journalFinalise expects the transactions in reverse order, so reverse the output in either case
|
||||||
let j' = if (_oldtimeclock iopts) then
|
let j' = if _oldtimeclock iopts then
|
||||||
-- timeclockEntriesToTransactionsSingle expects the entries to be in normal order,
|
-- timeclockEntriesToTransactionsSingle expects the entries to be in normal order,
|
||||||
-- but they have been parsed in reverse order, so reverse them before calling
|
-- but they have been parsed in reverse order, so reverse them before calling
|
||||||
j{jtxns = reverse $ timeclockEntriesToTransactionsSingle now $ reverse es, jparsetimeclockentries = []}
|
j{jtxns = reverse $ timeclockEntriesToTransactionsSingle now $ reverse es, jparsetimeclockentries = []}
|
||||||
else
|
else
|
||||||
-- We don't need to reverse these transactions
|
-- We don't need to reverse these transactions
|
||||||
-- since they are sorted inside of timeclockEntiresToTransactions
|
-- since they are sorted inside of timeclockEntriesToTransactions
|
||||||
j{jtxns = reverse $ timeclockEntriesToTransactions now es, jparsetimeclockentries = []}
|
j{jtxns = reverse $ timeclockEntriesToTransactions now es, jparsetimeclockentries = []}
|
||||||
return j'
|
return j'
|
||||||
where
|
where
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user