1 % Copyright (C) 2008 Eric Kow
3 % This program is free software; you can redistribute it and/or modify
4 % it under the terms of the GNU General Public License as published by
5 % the Free Software Foundation; either version 2, or (at your option)
8 % This program is distributed in the hope that it will be useful,
9 % but WITHOUT ANY WARRANTY; without even the implied warranty of
10 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 % GNU General Public License for more details.
13 % You should have received a copy of the GNU General Public License
14 % along with this program; see the file COPYING. If not, write to
15 % the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 % Boston, MA 02110-1301, USA.
18 To be loaded with GHCi
23 *DateTester>testDate "2008/05/22 10:34"
24 *DateTester>testDateAt "2006-03-22 09:36" "2008/05/22 10:34"
27 You could also just compile it if you want, but I don't see
31 module DateTester where
37 -- | 'testDate' @d@ shows the possible interpretations
38 -- for the date string @d@ and how they match against
40 testDate :: String -> IO ()
42 do now <- getClockTime >>= toCalendarTime
45 -- | 'testDate' @iso d@ shows the possible interpretations
46 -- for the date string @d@ and how they match against
47 -- the date represented by the ISO 8601 string @iso@
48 testDateAt :: String -> String -> IO ()
49 testDateAt iso d = testDateAtCal (readUTCDate iso) d
51 -- | helper function for 'testDate' and 'testDateAt'
52 testDateAtCal :: CalendarTime -> String -> IO ()
54 do ms <- getMatchers d
55 putStr . unlines . map (showMatcher c) $ ms
57 -- | 'showMatcher' @c dm@ tells us if @dm@ applies to
58 -- 'CalendarTime' @c@; or if @dm@ just represents the
59 -- failure to parse a date, in which case @c@ is moot.
60 showMatcher :: CalendarTime -> DateMatcher -> String
61 showMatcher now (DM n p m) =
62 "==== " ++ n ++ " ====\n" ++
64 Left err -> shows err ""
65 Right x -> show x ++ "\n" ++ (show $ m x now))