test and fix for auto-clockout of a future clockin

This commit is contained in:
Simon Michael 2009-04-01 05:00:08 +00:00
parent b616cdf0de
commit 38fd44917c
2 changed files with 12 additions and 6 deletions

View File

@ -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)

View File

@ -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`