diff options
Diffstat (limited to 'src/Index.hs')
| -rw-r--r-- | src/Index.hs | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/Index.hs b/src/Index.hs index 4b852bf..eedd1cd 100644 --- a/src/Index.hs +++ b/src/Index.hs @@ -466,24 +466,27 @@ indexCalendar (Index _ mp _) chan = do else coAll (scan IGV.! i) - coAll (scan IGV.! (i - 1)) | i <- [0 .. IGV.length scan - 1]]) -indexGetEventsDay :: Index -> Channel -> CountKind -> Day -> IO [(HMS, EventID, Event)] +-- | Returns the first and last day of this channel's logs, as well as the actual events on the requested day +indexGetEventsDay :: Index -> Channel -> CountKind -> Day -> IO ((Day, Day), [(HMS, EventID, Event)]) indexGetEventsDay index@(Index _ mp _) chan kind day = do ci <- readIORef (mp Map.! chan) + let firstlast = (ciStartDay ci, ciEndDay ci) let ymd = dayToYMD day if day < ciStartDay ci || day > ciEndDay ci - then return [] + then return (firstlast, []) else loadDay index chan ymd <&> \case Just (bs, _lineStarts) -> let events = parseLog bs - in case kind of - CKAll -> - [(hms, genEventID (YMDHMS ymd hms) off, ev) - | ((hms, ev), off) <- zip events [0..]] - CKCompressed -> - [(hms, genEventID (YMDHMS ymd hms) off, ev) - | ((hms, off), ev) <- compressEvents [((hms, off), ev) - | ((hms, ev), off) <- zip events [0..]]] - Nothing -> [] -- if the file doesn't exist, there ain't no events + events' = case kind of + CKAll -> + [(hms, genEventID (YMDHMS ymd hms) off, ev) + | ((hms, ev), off) <- zip events [0..]] + CKCompressed -> + [(hms, genEventID (YMDHMS ymd hms) off, ev) + | ((hms, off), ev) <- compressEvents [((hms, off), ev) + | ((hms, ev), off) <- zip events [0..]]] + in (firstlast, events') + Nothing -> (firstlast, []) -- if the file doesn't exist, there ain't no events -- utilities |
