5 module Main (main) where
6 import Control.Applicative
7 import Control.Applicative.Unicode
8 import Data.Ascii (Ascii)
9 import Data.Convertible.Base
12 import Data.Time.Asctime
13 import qualified Data.Time.HTTP as HTTP
14 import qualified Data.Time.RFC733 as RFC733
15 import qualified Data.Time.RFC1123 as RFC1123
17 import Prelude.Unicode
18 import Test.QuickCheck
21 main = mapM_ runTest tests
23 runTest ∷ Property → IO ()
25 = do r ← quickCheckResult prop
27 Success {} → return ()
28 GaveUp {} → exitFailure
29 Failure {} → exitFailure
30 NoExpectedFailure {} → exitFailure
32 instance Arbitrary Day where
33 arbitrary = ModifiedJulianDay <$> arbitrary
35 instance Arbitrary TimeOfDay where
37 = do h ← choose (0, 23)
40 return $ TimeOfDay h m (fromIntegral (s ∷ Int))
42 instance Arbitrary LocalTime where
43 arbitrary = LocalTime <$> arbitrary ⊛ arbitrary
45 instance Eq ZonedTime where
46 a == b = zonedTimeToUTC a ≡ zonedTimeToUTC b
48 instance Arbitrary TimeZone where
50 = do m ← choose (-1439, 1439)
53 return $ TimeZone m s n
55 instance Arbitrary ZonedTime where
56 arbitrary = ZonedTime <$> arbitrary ⊛ arbitrary
58 instance Arbitrary DiffTime where
59 arbitrary = secondsToDiffTime <$> choose (0, 86400)
61 instance Arbitrary UTCTime where
62 arbitrary = UTCTime <$> arbitrary ⊛ arbitrary
66 property ( convertUnsafe ( Tagged "Sun Nov 6 08:49:37 1994"
67 ∷ Tagged Asctime Ascii
72 , property ( ( Tagged "Sun Nov 6 08:49:37 1994"
73 ∷ Tagged Asctime Ascii
75 ≡ cs referenceLocalTime
78 , property $ \lt → lt ≡ convertUnsafe ( cs (lt ∷ LocalTime)
79 ∷ Tagged Asctime Ascii
83 , property ( RFC733.fromAscii "Sunday, 06-Nov-94 08:49:37 GMT"
84 ≡ Right referenceZonedTime )
86 , property ( "Sunday, 06-Nov-1994 08:49:37 GMT"
87 ≡ RFC733.toAscii referenceZonedTime )
89 , property $ \zt → Right zt ≡ RFC733.fromAscii (RFC733.toAscii zt)
92 , property ( RFC1123.fromAscii "Sun, 06 Nov 1994 08:49:37 GMT"
93 ≡ Right referenceZonedTime )
95 , property ( "Sun, 06 Nov 1994 08:49:37 GMT"
96 ≡ RFC1123.toAscii referenceZonedTime )
98 , property $ \zt → Right zt ≡ RFC1123.fromAscii (RFC1123.toAscii zt)
101 , property $ \ut → Right ut ≡ HTTP.fromAscii (HTTP.toAscii ut )
102 , property $ \ut → Right ut ≡ HTTP.fromAscii (untag (cs (ut2lt ut) ∷ Tagged Asctime Ascii))
103 , property $ \ut → Right ut ≡ HTTP.fromAscii (RFC733.toAscii (ut2zt ut))
104 , property $ \ut → Right ut ≡ HTTP.fromAscii (RFC1123.toAscii (ut2zt ut))
108 = LocalTime (ModifiedJulianDay 49662) (TimeOfDay 8 49 37)
111 = ZonedTime referenceLocalTime utc
113 ut2lt = utcToLocalTime utc
115 ut2zt = utcToZonedTime utc