Skip to content

Instantly share code, notes, and snippets.

@simonmichael
Created April 1, 2009 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonmichael/88523 to your computer and use it in GitHub Desktop.
Save simonmichael/88523 to your computer and use it in GitHub Desktop.
,"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