Created
April 1, 2009 03:34
-
-
Save simonmichael/88523 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
,"entriesFromTimeLogEntries" ~: do | |
-- setup common to entriesFromTimeLogEntries tests | |
today ← getCurrentDay | |
now ← getCurrentTime | |
tz ← getCurrentTimeZone | |
let clockin t a = TimeLogEntry 'i' t a | |
clockout t = TimeLogEntry 'o' t "" | |
yesterday = prevday today | |
mktime d s = LocalTime d $ fromMaybe midnight $ parseTime defaultTimeLocale "%H:%M:%S" s | |
noontoday = LocalTime today midday | |
ts `gives` ss = (map edescription $ entriesFromTimeLogEntries noontoday ts) `is` ss | |
-- five tests using the above, but not individually named | |
[] `gives` [] | |
-- we add missing clockout entries when needed | |
[clockin (mktime today "00:00:00") ""] `gives` ["00:00-12:00"] | |
-- splitting multi-day sessions at midnight | |
[clockin (mktime yesterday "23:00:00") ""] `gives` ["23:00-23:59","00:00-12:00"] | |
[clockin (mktime (addDays (-2) today) "23:00:00") ""] `gives` ["23:00-23:59","00:00-23:59","00:00-12:00"] | |
-- use the clockin time if it's in the future | |
let t = localTimeOfDay $ utcToLocalTime tz $ addUTCTime 100 now | |
s = formatTime defaultTimeLocale "%H:%M" t | |
[clockin (LocalTime today t) ""] `gives` [printf "%s-%s" s] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment