diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2017-03-16 01:19:07 +0100 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2017-03-16 01:19:07 +0100 |
commit | 3bfe0bdcb79b398a387e202c5150b5e6fd230d3a (patch) | |
tree | 8384b49048e84969a3a3440ed309b9c6e6b779de /Handler/List.hs | |
parent | 3ed9ec8ca70afb556f75d4e087043f4c67f50974 (diff) | |
download | bar-3bfe0bdcb79b398a387e202c5150b5e6fd230d3a.tar bar-3bfe0bdcb79b398a387e202c5150b5e6fd230d3a.tar.gz bar-3bfe0bdcb79b398a387e202c5150b5e6fd230d3a.tar.bz2 bar-3bfe0bdcb79b398a387e202c5150b5e6fd230d3a.tar.xz bar-3bfe0bdcb79b398a387e202c5150b5e6fd230d3a.zip |
More complicated date handling
Diffstat (limited to 'Handler/List.hs')
-rw-r--r-- | Handler/List.hs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/Handler/List.hs b/Handler/List.hs index 70f323a..4209651 100644 --- a/Handler/List.hs +++ b/Handler/List.hs | |||
@@ -19,9 +19,23 @@ import Database.Persist.Sql (Single(..), rawSql) | |||
19 | import Thermoprint.Client | 19 | import Thermoprint.Client |
20 | 20 | ||
21 | list :: Handler (Set (WithType Text)) | 21 | list :: Handler (Set (WithType Text)) |
22 | list = do | 22 | list = runDB $ do |
23 | (map (uncurry WithType . bimap unSingle unSingle) -> kinds) <- runDB $ rawSql "select reference.kind, kind.type from reference,kind where (not exists (select * from item where COALESCE(item.expires >= CURRENT_DATE, TRUE) and (item.norm_kind = reference.norm_kind))) and (reference.norm_kind = kind.norm_kind)" [] | 23 | today <- liftIO $ utctDay <$> getCurrentTime |
24 | return $ Set.fromList kinds | 24 | |
25 | items <- map entityVal <$> selectList [] [] | ||
26 | references <- Set.fromList <$> (withTypes . fmap entityVal =<< selectList [] []) | ||
27 | |||
28 | let | ||
29 | references' = Set.filter (isNothing . flip find items . matches) references | ||
30 | matches (Reference{..} `WithType` _) Item{..} | ||
31 | | today `isBefore` itemExpires = itemNormKind == referenceNormKind | ||
32 | | otherwise = False | ||
33 | |||
34 | isBefore _ DateNever = True | ||
35 | isBefore _ DateUnknown = False | ||
36 | isBefore d1 (DateKnown d2) = d1 < d2 | ||
37 | |||
38 | return $ Set.map (fmap referenceKind) references' | ||
25 | 39 | ||
26 | mkPrintout :: Set (WithType Text) -> Printout | 40 | mkPrintout :: Set (WithType Text) -> Printout |
27 | mkPrintout list = Printout ps | 41 | mkPrintout list = Printout ps |