diff --git a/Ledger/TimeLog.hs b/Ledger/TimeLog.hs index bc72e11a0..d10285441 100644 --- a/Ledger/TimeLog.hs +++ b/Ledger/TimeLog.hs @@ -26,18 +26,19 @@ instance Show TimeLog where -- midnight are split into days to give accurate per-day totals. entriesFromTimeLogEntries :: LocalTime -> [TimeLogEntry] -> [Entry] entriesFromTimeLogEntries _ [] = [] -entriesFromTimeLogEntries t [i] - | odate > idate = [entryFromTimeLogInOut i o'] ++ entriesFromTimeLogEntries t [i',o] +entriesFromTimeLogEntries now [i] + | odate > idate = [entryFromTimeLogInOut i o'] ++ entriesFromTimeLogEntries now [i',o] | otherwise = [entryFromTimeLogInOut i o] where - o = TimeLogEntry 'o' t "" + o = TimeLogEntry 'o' end "" + end = if itime > now then itime else now (itime,otime) = (tldatetime i,tldatetime o) (idate,odate) = (localDay itime,localDay otime) o' = o{tldatetime=itime{localDay=idate, localTimeOfDay=TimeOfDay 23 59 59}} i' = i{tldatetime=itime{localDay=addDays 1 idate, localTimeOfDay=midnight}} -entriesFromTimeLogEntries t (i:o:rest) - | odate > idate = [entryFromTimeLogInOut i o'] ++ entriesFromTimeLogEntries t (i':o:rest) - | otherwise = [entryFromTimeLogInOut i o] ++ entriesFromTimeLogEntries t rest +entriesFromTimeLogEntries now (i:o:rest) + | odate > idate = [entryFromTimeLogInOut i o'] ++ entriesFromTimeLogEntries now (i':o:rest) + | otherwise = [entryFromTimeLogInOut i o] ++ entriesFromTimeLogEntries now rest where (itime,otime) = (tldatetime i,tldatetime o) (idate,odate) = (localDay itime,localDay otime) diff --git a/Tests.hs b/Tests.hs index 9bf3b556c..a3d78ae79 100644 --- a/Tests.hs +++ b/Tests.hs @@ -337,6 +337,11 @@ tests = [ assertEntriesGiveStrings "auto-clock-out if needed" [clockin (mktime today "00:00:00") ""] ["00:00-12:00"] + let t = localTimeOfDay $ utcToLocalTime tz $ addUTCTime 100 now + s = formatTime defaultTimeLocale "%H:%M" t + assertEntriesGiveStrings "use the clockin time for auto-clockout if it's in the future" + [clockin (LocalTime today t) ""] + [printf "%s-%s" s s] ,"expandAccountNames" ~: do expandAccountNames ["assets:cash","assets:checking","expenses:vacation"] `is`