Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • Haskell-mouse/time
1 result
Show changes
...@@ -23,9 +23,10 @@ readShowProperty _ fmt val = ...@@ -23,9 +23,10 @@ readShowProperty _ fmt val =
case formatShowM fmt val of case formatShowM fmt val of
Nothing -> property Discard Nothing -> property Discard
Just str -> Just str ->
let found = formatParseM fmt str let
found = formatParseM fmt str
expected = Just val expected = Just val
in property $ in property $
if expected == found if expected == found
then succeeded then succeeded
else failed{reason = show str ++ ": expected " ++ (show expected) ++ ", found " ++ (show found)} else failed{reason = show str ++ ": expected " ++ (show expected) ++ ", found " ++ (show found)}
...@@ -68,13 +69,13 @@ instance Arbitrary (Durational CalendarDiffDays) where ...@@ -68,13 +69,13 @@ instance Arbitrary (Durational CalendarDiffDays) where
return $ MkDurational $ CalendarDiffDays mm dd return $ MkDurational $ CalendarDiffDays mm dd
instance Arbitrary (Durational CalendarDiffTime) where instance Arbitrary (Durational CalendarDiffTime) where
arbitrary = arbitrary = let
let limit = 40 * 86400 limit = 40 * 86400
picofactor = 10 ^ (12 :: Int) picofactor = 10 ^ (12 :: Int)
in do in do
mm <- choose (-10000, 10000) mm <- choose (-10000, 10000)
ss <- choose (negate limit * picofactor, limit * picofactor) ss <- choose (negate limit * picofactor, limit * picofactor)
return $ MkDurational $ CalendarDiffTime mm $ fromRational $ ss % picofactor return $ MkDurational $ CalendarDiffTime mm $ fromRational $ ss % picofactor
durationalFormat :: Format a -> Format (Durational a) durationalFormat :: Format a -> Format (Durational a)
durationalFormat (MkFormat sa ra) = MkFormat (\b -> sa $ unDurational b) (fmap MkDurational ra) durationalFormat (MkFormat sa ra) = MkFormat (\b -> sa $ unDurational b) (fmap MkDurational ra)
...@@ -126,59 +127,67 @@ testReadShowFormat = ...@@ -126,59 +127,67 @@ testReadShowFormat =
recurringIntervalFormat (localTimeFormat (calendarFormat fe) (timeOfDayFormat fe)) durationTimeFormat recurringIntervalFormat (localTimeFormat (calendarFormat fe) (timeOfDayFormat fe)) durationTimeFormat
] ]
testShowFormat :: String -> Format t -> String -> t -> TestTree testShowReadFormat :: (Show t, Eq t) => String -> Format t -> String -> t -> TestTree
testShowFormat name fmt str t = nameTest (name ++ ": " ++ str) $ assertEqual "" (Just str) $ formatShowM fmt t testShowReadFormat name fmt str val =
nameTest
(name ++ ": " ++ str)
[ nameTest "show" $ assertEqual "" (Just str) $ formatShowM fmt val
, nameTest "read" $ assertEqual "" (Just val) $ formatParseM fmt str
]
testReadFormat :: (Show t, Eq t) => String -> Format t -> String -> t -> TestTree
testReadFormat name fmt str val = nameTest (name ++ ": " ++ str) $ assertEqual "" (Just val) $ formatParseM fmt str
testShowFormats :: TestTree testShowFormats :: TestTree
testShowFormats = testShowFormats =
nameTest nameTest
"show format" "show format"
[ testShowFormat "durationDaysFormat" durationDaysFormat "P0D" $ CalendarDiffDays 0 0 [ testShowReadFormat "durationDaysFormat" durationDaysFormat "P0D" $ CalendarDiffDays 0 0
, testShowFormat "durationDaysFormat" durationDaysFormat "P4Y" $ CalendarDiffDays 48 0 , testShowReadFormat "durationDaysFormat" durationDaysFormat "P4Y" $ CalendarDiffDays 48 0
, testShowFormat "durationDaysFormat" durationDaysFormat "P7M" $ CalendarDiffDays 7 0 , testShowReadFormat "durationDaysFormat" durationDaysFormat "P7M" $ CalendarDiffDays 7 0
, testShowFormat "durationDaysFormat" durationDaysFormat "P5D" $ CalendarDiffDays 0 5 , testShowReadFormat "durationDaysFormat" durationDaysFormat "P5D" $ CalendarDiffDays 0 5
, testShowFormat "durationDaysFormat" durationDaysFormat "P2Y3M81D" $ CalendarDiffDays 27 81 , testShowReadFormat "durationDaysFormat" durationDaysFormat "P2Y3M81D" $ CalendarDiffDays 27 81
, testShowFormat "durationTimeFormat" durationTimeFormat "P0D" $ CalendarDiffTime 0 0 , testShowReadFormat "durationTimeFormat" durationTimeFormat "P0D" $ CalendarDiffTime 0 0
, testShowFormat "durationTimeFormat" durationTimeFormat "P4Y" $ CalendarDiffTime 48 0 , testShowReadFormat "durationTimeFormat" durationTimeFormat "P4Y" $ CalendarDiffTime 48 0
, testShowFormat "durationTimeFormat" durationTimeFormat "P7M" $ CalendarDiffTime 7 0 , testShowReadFormat "durationTimeFormat" durationTimeFormat "P7M" $ CalendarDiffTime 7 0
, testShowFormat "durationTimeFormat" durationTimeFormat "P5D" $ CalendarDiffTime 0 $ 5 * nominalDay , testShowReadFormat "durationTimeFormat" durationTimeFormat "P5D" $ CalendarDiffTime 0 $ 5 * nominalDay
, testShowFormat "durationTimeFormat" durationTimeFormat "P2Y3M81D" $ CalendarDiffTime 27 $ 81 * nominalDay , testShowReadFormat "durationTimeFormat" durationTimeFormat "P2Y3M81D" $ CalendarDiffTime 27 $ 81 * nominalDay
, testShowFormat "durationTimeFormat" durationTimeFormat "PT2H" $ CalendarDiffTime 0 $ 7200 , testShowReadFormat "durationTimeFormat" durationTimeFormat "PT2H" $ CalendarDiffTime 0 $ 7200
, testShowFormat "durationTimeFormat" durationTimeFormat "PT3M" $ CalendarDiffTime 0 $ 180 , testShowReadFormat "durationTimeFormat" durationTimeFormat "PT3M" $ CalendarDiffTime 0 $ 180
, testShowFormat "durationTimeFormat" durationTimeFormat "PT12S" $ CalendarDiffTime 0 $ 12 , testShowReadFormat "durationTimeFormat" durationTimeFormat "PT12S" $ CalendarDiffTime 0 $ 12
, testShowFormat "durationTimeFormat" durationTimeFormat "PT1M18.77634S" $ CalendarDiffTime 0 $ 78.77634 , testShowReadFormat "durationTimeFormat" durationTimeFormat "PT1M18.77634S" $ CalendarDiffTime 0 $ 78.77634
, testShowFormat "durationTimeFormat" durationTimeFormat "PT2H1M18.77634S" $ CalendarDiffTime 0 $ 7278.77634 , testShowReadFormat "durationTimeFormat" durationTimeFormat "PT2H1M18.77634S" $ CalendarDiffTime 0 $ 7278.77634
, testShowFormat "durationTimeFormat" durationTimeFormat "P5DT2H1M18.77634S" $ , testShowReadFormat "durationTimeFormat" durationTimeFormat "P5DT2H1M18.77634S" $
CalendarDiffTime 0 $ 5 * nominalDay + 7278.77634 CalendarDiffTime 0 $ 5 * nominalDay + 7278.77634
, testShowFormat "durationTimeFormat" durationTimeFormat "P7Y10M5DT2H1M18.77634S" $ , testShowReadFormat "durationTimeFormat" durationTimeFormat "P7Y10M5DT2H1M18.77634S" $
CalendarDiffTime 94 $ 5 * nominalDay + 7278.77634 CalendarDiffTime 94 $ 5 * nominalDay + 7278.77634
, testShowFormat "durationTimeFormat" durationTimeFormat "P7Y10MT2H1M18.77634S" $ , testShowReadFormat "durationTimeFormat" durationTimeFormat "P7Y10MT2H1M18.77634S" $
CalendarDiffTime 94 $ 7278.77634 CalendarDiffTime 94 $ 7278.77634
, testShowFormat "durationTimeFormat" durationTimeFormat "P8YT2H1M18.77634S" $ CalendarDiffTime 96 $ 7278.77634 , testShowReadFormat "durationTimeFormat" durationTimeFormat "P8YT2H1M18.77634S" $ CalendarDiffTime 96 $ 7278.77634
, testShowFormat "alternativeDurationDaysFormat" (alternativeDurationDaysFormat ExtendedFormat) "P0001-00-00" $ , testShowReadFormat "alternativeDurationDaysFormat" (alternativeDurationDaysFormat ExtendedFormat) "P0001-00-00" $
CalendarDiffDays 12 0 CalendarDiffDays 12 0
, testShowFormat "alternativeDurationDaysFormat" (alternativeDurationDaysFormat ExtendedFormat) "P0002-03-29" $ , testShowReadFormat "alternativeDurationDaysFormat" (alternativeDurationDaysFormat ExtendedFormat) "P0002-03-29" $
CalendarDiffDays 27 29 CalendarDiffDays 27 29
, testShowFormat "alternativeDurationDaysFormat" (alternativeDurationDaysFormat ExtendedFormat) "P0561-08-29" $ , testShowReadFormat "alternativeDurationDaysFormat" (alternativeDurationDaysFormat ExtendedFormat) "P0561-08-29" $
CalendarDiffDays (561 * 12 + 8) 29 CalendarDiffDays (561 * 12 + 8) 29
, testShowFormat , testShowReadFormat
"alternativeDurationTimeFormat" "alternativeDurationTimeFormat"
(alternativeDurationTimeFormat ExtendedFormat) (alternativeDurationTimeFormat ExtendedFormat)
"P0000-00-01T00:00:00" "P0000-00-01T00:00:00"
$ CalendarDiffTime 0 86400 $ CalendarDiffTime 0 86400
, testShowFormat , testShowReadFormat
"alternativeDurationTimeFormat" "alternativeDurationTimeFormat"
(alternativeDurationTimeFormat ExtendedFormat) (alternativeDurationTimeFormat ExtendedFormat)
"P0007-10-05T02:01:18.77634" "P0007-10-05T02:01:18.77634"
$ CalendarDiffTime 94 $ 5 * nominalDay + 7278.77634 $ CalendarDiffTime 94 $ 5 * nominalDay + 7278.77634
, testShowFormat , testShowReadFormat
"alternativeDurationTimeFormat" "alternativeDurationTimeFormat"
(alternativeDurationTimeFormat ExtendedFormat) (alternativeDurationTimeFormat ExtendedFormat)
"P4271-10-05T02:01:18.77634" "P4271-10-05T02:01:18.77634"
$ CalendarDiffTime (12 * 4271 + 10) $ 5 * nominalDay + 7278.77634 $ CalendarDiffTime (12 * 4271 + 10) $ 5 * nominalDay + 7278.77634
, testShowFormat "centuryFormat" centuryFormat "02" 2 , testShowReadFormat "centuryFormat" centuryFormat "02" 2
, testShowFormat "centuryFormat" centuryFormat "21" 21 , testShowReadFormat "centuryFormat" centuryFormat "21" 21
, testShowFormat , testShowReadFormat
"intervalFormat etc." "intervalFormat etc."
( intervalFormat ( intervalFormat
(localTimeFormat (calendarFormat ExtendedFormat) (timeOfDayFormat ExtendedFormat)) (localTimeFormat (calendarFormat ExtendedFormat) (timeOfDayFormat ExtendedFormat))
...@@ -188,7 +197,7 @@ testShowFormats = ...@@ -188,7 +197,7 @@ testShowFormats =
( LocalTime (fromGregorian 2015 6 13) (TimeOfDay 21 13 56) ( LocalTime (fromGregorian 2015 6 13) (TimeOfDay 21 13 56)
, CalendarDiffTime 14 $ 7 * nominalDay + 5 * 3600 + 33 * 60 + 2.34 , CalendarDiffTime 14 $ 7 * nominalDay + 5 * 3600 + 33 * 60 + 2.34
) )
, testShowFormat , testShowReadFormat
"recurringIntervalFormat etc." "recurringIntervalFormat etc."
( recurringIntervalFormat ( recurringIntervalFormat
(localTimeFormat (calendarFormat ExtendedFormat) (timeOfDayFormat ExtendedFormat)) (localTimeFormat (calendarFormat ExtendedFormat) (timeOfDayFormat ExtendedFormat))
...@@ -199,75 +208,105 @@ testShowFormats = ...@@ -199,75 +208,105 @@ testShowFormats =
, LocalTime (fromGregorian 2015 6 13) (TimeOfDay 21 13 56) , LocalTime (fromGregorian 2015 6 13) (TimeOfDay 21 13 56)
, CalendarDiffTime 14 $ 7 * nominalDay + 5 * 3600 + 33 * 60 + 2.34 , CalendarDiffTime 14 $ 7 * nominalDay + 5 * 3600 + 33 * 60 + 2.34
) )
, testShowFormat , testShowReadFormat
"recurringIntervalFormat etc." "recurringIntervalFormat etc."
(recurringIntervalFormat (calendarFormat ExtendedFormat) durationDaysFormat) (recurringIntervalFormat (calendarFormat ExtendedFormat) durationDaysFormat)
"R74/2015-06-13/P1Y2M7D" "R74/2015-06-13/P1Y2M7D"
(74, fromGregorian 2015 6 13, CalendarDiffDays 14 7) (74, fromGregorian 2015 6 13, CalendarDiffDays 14 7)
, testShowFormat "timeOffsetFormat" iso8601Format "-06:30" (minutesToTimeZone (-390)) , testShowReadFormat "timeOffsetFormat" iso8601Format "-06:30" (minutesToTimeZone (-390))
, testShowFormat "timeOffsetFormat" iso8601Format "+00:00" (minutesToTimeZone 0) , testShowReadFormat "timeOffsetFormat" iso8601Format "-06:00" (minutesToTimeZone (-360))
, testShowFormat "timeOffsetFormat" (timeOffsetFormat BasicFormat) "+0000" (minutesToTimeZone 0) , testReadFormat "timeOffsetFormat" iso8601Format "-06" (minutesToTimeZone (-360))
, testShowFormat "timeOffsetFormat" iso8601Format "+00:10" (minutesToTimeZone 10) , testShowReadFormat "timeOffsetFormat" iso8601Format "+11:00" (minutesToTimeZone 660)
, testShowFormat "timeOffsetFormat" iso8601Format "-00:10" (minutesToTimeZone (-10)) , testReadFormat "timeOffsetFormat" iso8601Format "+11" (minutesToTimeZone 660)
, testShowFormat "timeOffsetFormat" iso8601Format "+01:35" (minutesToTimeZone 95) , testShowReadFormat "timeOffsetFormat" iso8601Format "+00:00" (minutesToTimeZone 0)
, testShowFormat "timeOffsetFormat" iso8601Format "-01:35" (minutesToTimeZone (-95)) , testReadFormat "timeOffsetFormat" iso8601Format "+00" (minutesToTimeZone 0)
, testShowFormat "timeOffsetFormat" (timeOffsetFormat BasicFormat) "+0135" (minutesToTimeZone 95) , testReadFormat "timeOffsetFormat" iso8601Format "-00:00" (minutesToTimeZone 0)
, testShowFormat "timeOffsetFormat" (timeOffsetFormat BasicFormat) "-0135" (minutesToTimeZone (-95)) , testReadFormat "timeOffsetFormat" iso8601Format "-00" (minutesToTimeZone 0)
, testShowFormat , testShowReadFormat "timeOffsetFormat" (timeOffsetFormat BasicFormat) "+0000" (minutesToTimeZone 0)
, testReadFormat "timeOffsetFormat" (timeOffsetFormat BasicFormat) "+00" (minutesToTimeZone 0)
, testReadFormat "timeOffsetFormat" (timeOffsetFormat BasicFormat) "-0000" (minutesToTimeZone 0)
, testReadFormat "timeOffsetFormat" (timeOffsetFormat BasicFormat) "-00" (minutesToTimeZone 0)
, testShowReadFormat "timeOffsetFormat" iso8601Format "+00:10" (minutesToTimeZone 10)
, testShowReadFormat "timeOffsetFormat" iso8601Format "-00:10" (minutesToTimeZone (-10))
, testShowReadFormat "timeOffsetFormat" iso8601Format "+01:35" (minutesToTimeZone 95)
, testShowReadFormat "timeOffsetFormat" iso8601Format "-01:35" (minutesToTimeZone (-95))
, testShowReadFormat "timeOffsetFormat" (timeOffsetFormat BasicFormat) "+0135" (minutesToTimeZone 95)
, testShowReadFormat "timeOffsetFormat" (timeOffsetFormat BasicFormat) "-0135" (minutesToTimeZone (-95))
, testShowReadFormat
"timeOffsetFormat" "timeOffsetFormat"
(timeOffsetFormat BasicFormat) (timeOffsetFormat BasicFormat)
"-1100" "-1100"
(minutesToTimeZone $ negate $ 11 * 60) (minutesToTimeZone $ negate $ 11 * 60)
, testShowFormat "timeOffsetFormat" (timeOffsetFormat BasicFormat) "+1015" (minutesToTimeZone $ 615) , testShowReadFormat "timeOffsetFormat" (timeOffsetFormat BasicFormat) "+1015" (minutesToTimeZone $ 615)
, testShowFormat , testShowReadFormat
"zonedTimeFormat" "zonedTimeFormat"
iso8601Format iso8601Format
"2024-07-06T08:45:56.553-06:30" "2024-07-06T08:45:56.553-06:30"
(ZonedTime (LocalTime (fromGregorian 2024 07 06) (TimeOfDay 8 45 56.553)) (minutesToTimeZone (-390))) (ZonedTime (LocalTime (fromGregorian 2024 07 06) (TimeOfDay 8 45 56.553)) (minutesToTimeZone (-390)))
, testShowFormat , testShowReadFormat
"zonedTimeFormat"
iso8601Format
"2024-07-06T08:45:56.553-06:00"
(ZonedTime (LocalTime (fromGregorian 2024 07 06) (TimeOfDay 8 45 56.553)) (minutesToTimeZone (-360)))
, testReadFormat
"zonedTimeFormat"
iso8601Format
"2024-07-06T08:45:56.553-06"
(ZonedTime (LocalTime (fromGregorian 2024 07 06) (TimeOfDay 8 45 56.553)) (minutesToTimeZone (-360)))
, testShowReadFormat
"zonedTimeFormat" "zonedTimeFormat"
iso8601Format iso8601Format
"2024-07-06T08:45:56.553+06:30" "2024-07-06T08:45:56.553+06:30"
(ZonedTime (LocalTime (fromGregorian 2024 07 06) (TimeOfDay 8 45 56.553)) (minutesToTimeZone 390)) (ZonedTime (LocalTime (fromGregorian 2024 07 06) (TimeOfDay 8 45 56.553)) (minutesToTimeZone 390))
, testShowFormat , testShowReadFormat
"zonedTimeFormat"
iso8601Format
"2024-07-06T08:45:56.553+06:00"
(ZonedTime (LocalTime (fromGregorian 2024 07 06) (TimeOfDay 8 45 56.553)) (minutesToTimeZone 360))
, testReadFormat
"zonedTimeFormat"
iso8601Format
"2024-07-06T08:45:56.553+06"
(ZonedTime (LocalTime (fromGregorian 2024 07 06) (TimeOfDay 8 45 56.553)) (minutesToTimeZone 360))
, testShowReadFormat
"utcTimeFormat" "utcTimeFormat"
iso8601Format iso8601Format
"2024-07-06T08:45:56.553Z" "2024-07-06T08:45:56.553Z"
(UTCTime (fromGregorian 2024 07 06) (timeOfDayToTime $ TimeOfDay 8 45 56.553)) (UTCTime (fromGregorian 2024 07 06) (timeOfDayToTime $ TimeOfDay 8 45 56.553))
, testShowFormat , testShowReadFormat
"utcTimeFormat" "utcTimeFormat"
iso8601Format iso8601Format
"2028-12-31T23:59:60.9Z" "2028-12-31T23:59:60.9Z"
(UTCTime (fromGregorian 2028 12 31) (timeOfDayToTime $ TimeOfDay 23 59 60.9)) (UTCTime (fromGregorian 2028 12 31) (timeOfDayToTime $ TimeOfDay 23 59 60.9))
, testShowFormat "weekDateFormat" (weekDateFormat ExtendedFormat) "1994-W52-7" (fromGregorian 1995 1 1) , testShowReadFormat "weekDateFormat" (weekDateFormat ExtendedFormat) "1994-W52-7" (fromGregorian 1995 1 1)
, testShowFormat "weekDateFormat" (weekDateFormat ExtendedFormat) "1995-W01-1" (fromGregorian 1995 1 2) , testShowReadFormat "weekDateFormat" (weekDateFormat ExtendedFormat) "1995-W01-1" (fromGregorian 1995 1 2)
, testShowFormat "weekDateFormat" (weekDateFormat ExtendedFormat) "1996-W52-7" (fromGregorian 1996 12 29) , testShowReadFormat "weekDateFormat" (weekDateFormat ExtendedFormat) "1996-W52-7" (fromGregorian 1996 12 29)
, testShowFormat "weekDateFormat" (weekDateFormat ExtendedFormat) "1997-W01-2" (fromGregorian 1996 12 31) , testShowReadFormat "weekDateFormat" (weekDateFormat ExtendedFormat) "1997-W01-2" (fromGregorian 1996 12 31)
, testShowFormat "weekDateFormat" (weekDateFormat ExtendedFormat) "1997-W01-3" (fromGregorian 1997 1 1) , testShowReadFormat "weekDateFormat" (weekDateFormat ExtendedFormat) "1997-W01-3" (fromGregorian 1997 1 1)
, testShowFormat "weekDateFormat" (weekDateFormat ExtendedFormat) "1974-W32-6" (fromGregorian 1974 8 10) , testShowReadFormat "weekDateFormat" (weekDateFormat ExtendedFormat) "1974-W32-6" (fromGregorian 1974 8 10)
, testShowFormat "weekDateFormat" (weekDateFormat BasicFormat) "1974W326" (fromGregorian 1974 8 10) , testShowReadFormat "weekDateFormat" (weekDateFormat BasicFormat) "1974W326" (fromGregorian 1974 8 10)
, testShowFormat "weekDateFormat" (weekDateFormat ExtendedFormat) "1995-W05-6" (fromGregorian 1995 2 4) , testShowReadFormat "weekDateFormat" (weekDateFormat ExtendedFormat) "1995-W05-6" (fromGregorian 1995 2 4)
, testShowFormat "weekDateFormat" (weekDateFormat BasicFormat) "1995W056" (fromGregorian 1995 2 4) , testShowReadFormat "weekDateFormat" (weekDateFormat BasicFormat) "1995W056" (fromGregorian 1995 2 4)
, testShowFormat , testShowReadFormat
"weekDateFormat" "weekDateFormat"
(expandedWeekDateFormat 6 ExtendedFormat) (expandedWeekDateFormat 6 ExtendedFormat)
"+001995-W05-6" "+001995-W05-6"
(fromGregorian 1995 2 4) (fromGregorian 1995 2 4)
, testShowFormat "weekDateFormat" (expandedWeekDateFormat 6 BasicFormat) "+001995W056" (fromGregorian 1995 2 4) , testShowReadFormat "weekDateFormat" (expandedWeekDateFormat 6 BasicFormat) "+001995W056" (fromGregorian 1995 2 4)
, testShowFormat "ordinalDateFormat" (ordinalDateFormat ExtendedFormat) "1846-235" (fromGregorian 1846 8 23) , testShowReadFormat "ordinalDateFormat" (ordinalDateFormat ExtendedFormat) "1846-235" (fromGregorian 1846 8 23)
, testShowFormat "ordinalDateFormat" (ordinalDateFormat BasicFormat) "1844236" (fromGregorian 1844 8 23) , testShowReadFormat "ordinalDateFormat" (ordinalDateFormat BasicFormat) "1844236" (fromGregorian 1844 8 23)
, testShowFormat , testShowReadFormat
"ordinalDateFormat" "ordinalDateFormat"
(expandedOrdinalDateFormat 5 ExtendedFormat) (expandedOrdinalDateFormat 5 ExtendedFormat)
"+01846-235" "+01846-235"
(fromGregorian 1846 8 23) (fromGregorian 1846 8 23)
, testShowFormat "hourMinuteFormat" (hourMinuteFormat ExtendedFormat) "13:17.25" (TimeOfDay 13 17 15) , testShowReadFormat "hourMinuteFormat" (hourMinuteFormat ExtendedFormat) "13:17.25" (TimeOfDay 13 17 15)
, testShowFormat "hourMinuteFormat" (hourMinuteFormat ExtendedFormat) "01:12.4" (TimeOfDay 1 12 24) , testShowReadFormat "hourMinuteFormat" (hourMinuteFormat ExtendedFormat) "01:12.4" (TimeOfDay 1 12 24)
, testShowFormat "hourMinuteFormat" (hourMinuteFormat BasicFormat) "1317.25" (TimeOfDay 13 17 15) , testShowReadFormat "hourMinuteFormat" (hourMinuteFormat BasicFormat) "1317.25" (TimeOfDay 13 17 15)
, testShowFormat "hourMinuteFormat" (hourMinuteFormat BasicFormat) "0112.4" (TimeOfDay 1 12 24) , testShowReadFormat "hourMinuteFormat" (hourMinuteFormat BasicFormat) "0112.4" (TimeOfDay 1 12 24)
, testShowFormat "hourFormat" hourFormat "22" (TimeOfDay 22 0 0) , testShowReadFormat "hourFormat" hourFormat "22" (TimeOfDay 22 0 0)
, testShowFormat "hourFormat" hourFormat "06" (TimeOfDay 6 0 0) , testShowReadFormat "hourFormat" hourFormat "06" (TimeOfDay 6 0 0)
, testShowFormat "hourFormat" hourFormat "18.9475" (TimeOfDay 18 56 51) , testShowReadFormat "hourFormat" hourFormat "18.9475" (TimeOfDay 18 56 51)
] ]
testISO8601 :: TestTree testISO8601 :: TestTree
......
...@@ -40,15 +40,15 @@ data FormatCode pf t = MkFormatCode ...@@ -40,15 +40,15 @@ data FormatCode pf t = MkFormatCode
} }
instance Show (FormatCode pf t) where instance Show (FormatCode pf t) where
show (MkFormatCode m w a s) = show (MkFormatCode m w a s) = let
let ms = m ms = m
ws = fromMaybe "" $ fmap show w ws = fromMaybe "" $ fmap show w
as = as =
if a if a
then "E" then "E"
else "" else ""
ss = [s] ss = [s]
in '%' : (ms <> ws <> as <> ss) in '%' : (ms <> ws <> as <> ss)
formatCode :: FormatTime t => FormatCode pf t -> t -> String formatCode :: FormatTime t => FormatCode pf t -> t -> String
formatCode fc = format $ show fc formatCode fc = format $ show fc
...@@ -65,22 +65,19 @@ minCodeWidth :: Char -> Int ...@@ -65,22 +65,19 @@ minCodeWidth :: Char -> Int
minCodeWidth _ = 0 minCodeWidth _ = 0
fcShrink :: FormatCode pf t -> [FormatCode pf t] fcShrink :: FormatCode pf t -> [FormatCode pf t]
fcShrink fc = fcShrink fc = let
let fc1 = fc1 = case fcWidth fc of
case fcWidth fc of Nothing -> []
Nothing -> [] Just w
Just w | w > (minCodeWidth $ fcSpecifier fc) -> [fc{fcWidth = Nothing}, fc{fcWidth = Just $ w - 1}]
| w > (minCodeWidth $ fcSpecifier fc) -> [fc{fcWidth = Nothing}, fc{fcWidth = Just $ w - 1}] Just _ -> [fc{fcWidth = Nothing}]
Just _ -> [fc{fcWidth = Nothing}] fc2 = case fcAlt fc of
fc2 = False -> []
case fcAlt fc of True -> [fc{fcAlt = False}]
False -> [] fc3 = case fcModifier fc of
True -> [fc{fcAlt = False}] "" -> []
fc3 = _ -> [fc{fcModifier = ""}]
case fcModifier fc of in fc1 ++ fc2 ++ fc3
"" -> []
_ -> [fc{fcModifier = ""}]
in fc1 ++ fc2 ++ fc3
instance HasFormatCodes t => Arbitrary (FormatCode FormatOnly t) where instance HasFormatCodes t => Arbitrary (FormatCode FormatOnly t) where
arbitrary = do arbitrary = do
...@@ -156,11 +153,11 @@ extests = ...@@ -156,11 +153,11 @@ extests =
) )
readTest :: (Eq a, Show a, Read a) => [(a, String)] -> String -> TestTree readTest :: (Eq a, Show a, Read a) => [(a, String)] -> String -> TestTree
readTest expected target = readTest expected target = let
let found = reads target found = reads target
result = assertEqual "" expected found result = assertEqual "" expected found
name = show target name = show target
in Test.Tasty.HUnit.testCase name result in Test.Tasty.HUnit.testCase name result
readTestsParensSpaces :: readTestsParensSpaces ::
forall a. forall a.
...@@ -192,9 +189,9 @@ readTests = ...@@ -192,9 +189,9 @@ readTests =
testGroup testGroup
"read times" "read times"
[ readTestsParensSpaces testDay "1912-07-08" [ readTestsParensSpaces testDay "1912-07-08"
, --readTestsParensSpaces testDay "1912-7-8", , -- readTestsParensSpaces testDay "1912-7-8",
readTestsParensSpaces testTimeOfDay "08:04:02" readTestsParensSpaces testTimeOfDay "08:04:02"
--,readTestsParensSpaces testTimeOfDay "8:4:2" -- ,readTestsParensSpaces testTimeOfDay "8:4:2"
] ]
where where
testDay = fromGregorian 1912 7 8 testDay = fromGregorian 1912 7 8
...@@ -230,11 +227,11 @@ simpleFormatTests = ...@@ -230,11 +227,11 @@ simpleFormatTests =
] ]
where where
readsTest :: (Show a, Eq a, ParseTime a) => [(a, String)] -> String -> String -> TestTree readsTest :: (Show a, Eq a, ParseTime a) => [(a, String)] -> String -> String -> TestTree
readsTest expected formatStr target = readsTest expected formatStr target = let
let found = readSTime False defaultTimeLocale formatStr target found = readSTime False defaultTimeLocale formatStr target
result = assertEqual "" expected found result = assertEqual "" expected found
name = (show formatStr) ++ " of " ++ (show target) name = (show formatStr) ++ " of " ++ (show target)
in Test.Tasty.HUnit.testCase name result in Test.Tasty.HUnit.testCase name result
spacingTests :: (Show t, Eq t, ParseTime t) => t -> String -> String -> TestTree spacingTests :: (Show t, Eq t, ParseTime t) => t -> String -> String -> TestTree
spacingTests expected formatStr target = spacingTests expected formatStr target =
...@@ -268,24 +265,20 @@ badParseTests :: TestTree ...@@ -268,24 +265,20 @@ badParseTests :: TestTree
badParseTests = testGroup "bad" [parseTest False (Nothing :: Maybe Day) "%Y" ""] badParseTests = testGroup "bad" [parseTest False (Nothing :: Maybe Day) "%Y" ""]
parseYMD :: Day -> TestTree parseYMD :: Day -> TestTree
parseYMD day = parseYMD day = case toGregorian day of
case toGregorian day of (y, m, d) -> parseTest False (Just day) "%Y%m%d" ((show y) ++ (show2 m) ++ (show2 d))
(y, m, d) -> parseTest False (Just day) "%Y%m%d" ((show y) ++ (show2 m) ++ (show2 d))
parseYearDayD :: Day -> TestTree parseYearDayD :: Day -> TestTree
parseYearDayD day = parseYearDayD day = case toGregorian day of
case toGregorian day of (y, m, d) -> parseTest False (Just day) "%Y %m %d" ((show y) ++ " " ++ (show2 m) ++ " " ++ (show2 d))
(y, m, d) -> parseTest False (Just day) "%Y %m %d" ((show y) ++ " " ++ (show2 m) ++ " " ++ (show2 d))
parseYearDayE :: Day -> TestTree parseYearDayE :: Day -> TestTree
parseYearDayE day = parseYearDayE day = case toGregorian day of
case toGregorian day of (y, m, d) -> parseTest False (Just day) "%Y %-m %e" ((show y) ++ " " ++ (show m) ++ " " ++ (show d))
(y, m, d) -> parseTest False (Just day) "%Y %-m %e" ((show y) ++ " " ++ (show m) ++ " " ++ (show d))
-- | 1969 - 2068 -- | 1969 - 2068
expectedYear :: Integer -> Integer expectedYear :: Integer -> Integer
expectedYear i expectedYear i | i >= 69 = 1900 + i
| i >= 69 = 1900 + i
expectedYear i = 2000 + i expectedYear i = 2000 + i
show2 :: (Show n, Integral n) => n -> String show2 :: (Show n, Integral n) => n -> String
...@@ -305,18 +298,18 @@ parseCentury int c = ...@@ -305,18 +298,18 @@ parseCentury int c =
parseTest False (Just (fromGregorian (c * 100) 1 1)) ("%-C" ++ int ++ "%y") ((show c) ++ int ++ "00") parseTest False (Just (fromGregorian (c * 100) 1 1)) ("%-C" ++ int ++ "%y") ((show c) ++ int ++ "00")
parseTest :: (Show t, Eq t, ParseTime t) => Bool -> Maybe t -> String -> String -> TestTree parseTest :: (Show t, Eq t, ParseTime t) => Bool -> Maybe t -> String -> String -> TestTree
parseTest sp expected formatStr target = parseTest sp expected formatStr target = let
let found = parse sp formatStr target found = parse sp formatStr target
result = assertEqual "" expected found result = assertEqual "" expected found
name = name =
(show formatStr) (show formatStr)
++ " of " ++ " of "
++ (show target) ++ (show target)
++ ( if sp ++ ( if sp
then " allowing spaces" then " allowing spaces"
else "" else ""
) )
in Test.Tasty.HUnit.testCase name result in Test.Tasty.HUnit.testCase name result
{- {-
readsTest :: forall t. (Show t, Eq t, ParseTime t) => Maybe t -> String -> String -> TestTree readsTest :: forall t. (Show t, Eq t, ParseTime t) => Maybe t -> String -> String -> TestTree
...@@ -328,10 +321,8 @@ enumAdd i a = toEnum (i + fromEnum a) ...@@ -328,10 +321,8 @@ enumAdd i a = toEnum (i + fromEnum a)
getMilZoneLetter :: Int -> Char getMilZoneLetter :: Int -> Char
getMilZoneLetter 0 = 'Z' getMilZoneLetter 0 = 'Z'
getMilZoneLetter h getMilZoneLetter h | h < 0 = enumAdd (negate h) 'M'
| h < 0 = enumAdd (negate h) 'M' getMilZoneLetter h | h < 10 = enumAdd (h - 1) 'A'
getMilZoneLetter h
| h < 10 = enumAdd (h - 1) 'A'
getMilZoneLetter h = enumAdd (h - 10) 'K' getMilZoneLetter h = enumAdd (h - 10) 'K'
getMilZone :: Int -> TimeZone getMilZone :: Int -> TimeZone
...@@ -373,9 +364,9 @@ compareParse expected fmt text = compareResult' (", parsing " ++ (show text)) (J ...@@ -373,9 +364,9 @@ compareParse expected fmt text = compareResult' (", parsing " ++ (show text)) (J
-- --
test_parse_format :: (FormatTime t, ParseTime t, Show t) => String -> t -> (String, String, Maybe t) test_parse_format :: (FormatTime t, ParseTime t, Show t) => String -> t -> (String, String, Maybe t)
test_parse_format f t = test_parse_format f t = let
let s = format f t s = format f t
in (show t, s, parse False f s `asTypeOf` Just t) in (show t, s, parse False f s `asTypeOf` Just t)
-- --
...@@ -391,6 +382,9 @@ prop_read_show_ZonedUTC t = compareResult (Just $ zonedTimeToUTC t) (readMaybe ( ...@@ -391,6 +382,9 @@ prop_read_show_ZonedUTC t = compareResult (Just $ zonedTimeToUTC t) (readMaybe (
prop_read_show_LocalUTC :: LocalTime -> Result prop_read_show_LocalUTC :: LocalTime -> Result
prop_read_show_LocalUTC t = compareResult (Just $ localTimeToUTC utc t) (readMaybe (show t)) prop_read_show_LocalUTC t = compareResult (Just $ localTimeToUTC utc t) (readMaybe (show t))
prop_read_show_UTC_no_TZ :: UTCTime -> Result
prop_read_show_UTC_no_TZ t = compareResult (Just t) $ readMaybe $ show $ utcToLocalTime utc t
-- --
-- * special show functions -- * special show functions
...@@ -411,16 +405,16 @@ prop_parse_showOrdinalDate d = compareParse d "%Y-%j" (showOrdinalDate d) ...@@ -411,16 +405,16 @@ prop_parse_showOrdinalDate d = compareParse d "%Y-%j" (showOrdinalDate d)
-- --
prop_fromMondayStartWeek :: Day -> Result prop_fromMondayStartWeek :: Day -> Result
prop_fromMondayStartWeek d = prop_fromMondayStartWeek d = let
let (w, wd) = mondayStartWeek d (w, wd) = mondayStartWeek d
(y, _, _) = toGregorian d (y, _, _) = toGregorian d
in compareResult d (fromMondayStartWeek y w wd) in compareResult d (fromMondayStartWeek y w wd)
prop_fromSundayStartWeek :: Day -> Result prop_fromSundayStartWeek :: Day -> Result
prop_fromSundayStartWeek d = prop_fromSundayStartWeek d = let
let (w, wd) = sundayStartWeek d (w, wd) = sundayStartWeek d
(y, _, _) = toGregorian d (y, _, _) = toGregorian d
in compareResult d (fromSundayStartWeek y w wd) in compareResult d (fromSundayStartWeek y w wd)
-- t == parse (format t) -- t == parse (format t)
prop_parse_format :: (Eq t, FormatTime t, ParseTime t, Show t) => FormatString t -> t -> Result prop_parse_format :: (Eq t, FormatTime t, ParseTime t, Show t) => FormatString t -> t -> Result
...@@ -450,13 +444,13 @@ prop_format_parse_format :: ...@@ -450,13 +444,13 @@ prop_format_parse_format ::
FormatCode ParseAndFormat t -> FormatCode ParseAndFormat t ->
t -> t ->
Result Result
prop_format_parse_format _ fc v = prop_format_parse_format _ fc v = let
let s1 = formatCode fc v s1 = formatCode fc v
ms1 = in1970 (fmap (formatCode fc) (incompleteS :: Maybe t)) (fcSpecifier fc) s1 ms1 = in1970 (fmap (formatCode fc) (incompleteS :: Maybe t)) (fcSpecifier fc) s1
mv2 :: Maybe t mv2 :: Maybe t
mv2 = parseCode fc s1 mv2 = parseCode fc s1
ms2 = fmap (formatCode fc) mv2 ms2 = fmap (formatCode fc) mv2
in compareResult ms1 ms2 in compareResult ms1 ms2
instance HasFormatCodes Day where instance HasFormatCodes Day where
allFormatCodes _ = [(False, s) | s <- "DFxYyCBbhmdejfVUW"] allFormatCodes _ = [(False, s) | s <- "DFxYyCBbhmdejfVUW"]
...@@ -556,22 +550,22 @@ allTypes f = ...@@ -556,22 +550,22 @@ allTypes f =
allLeapSecondTypes :: allLeapSecondTypes ::
(forall t. (Eq t, Show t, Arbitrary t, FormatTime t, ParseTime t, HasFormatCodes t) => String -> t -> r) -> (forall t. (Eq t, Show t, Arbitrary t, FormatTime t, ParseTime t, HasFormatCodes t) => String -> t -> r) ->
[r] [r]
allLeapSecondTypes f = allLeapSecondTypes f = let
let day :: Day day :: Day
day = fromGregorian 2000 01 01 day = fromGregorian 2000 01 01
lsTimeOfDay :: TimeOfDay lsTimeOfDay :: TimeOfDay
lsTimeOfDay = TimeOfDay 23 59 60.5 lsTimeOfDay = TimeOfDay 23 59 60.5
lsLocalTime :: LocalTime lsLocalTime :: LocalTime
lsLocalTime = LocalTime day lsTimeOfDay lsLocalTime = LocalTime day lsTimeOfDay
lsZonedTime :: ZonedTime lsZonedTime :: ZonedTime
lsZonedTime = ZonedTime lsLocalTime utc lsZonedTime = ZonedTime lsLocalTime utc
lsUTCTime :: UTCTime lsUTCTime :: UTCTime
lsUTCTime = UTCTime day 86400.5 lsUTCTime = UTCTime day 86400.5
in [ f "TimeOfDay" lsTimeOfDay in [ f "TimeOfDay" lsTimeOfDay
, f "LocalTime" lsLocalTime , f "LocalTime" lsLocalTime
, f "ZonedTime" lsZonedTime , f "ZonedTime" lsZonedTime
, f "UTCTime" lsUTCTime , f "UTCTime" lsUTCTime
] ]
parseEmptyTest :: parseEmptyTest ::
forall t. forall t.
...@@ -629,11 +623,12 @@ readShowTests = ...@@ -629,11 +623,12 @@ readShowTests =
, nameTest "UTCTime" (prop_read_show :: UTCTime -> Result) , nameTest "UTCTime" (prop_read_show :: UTCTime -> Result)
, nameTest "UTCTime (zoned)" prop_read_show_ZonedUTC , nameTest "UTCTime (zoned)" prop_read_show_ZonedUTC
, nameTest "UTCTime (local)" prop_read_show_LocalUTC , nameTest "UTCTime (local)" prop_read_show_LocalUTC
, nameTest "UTCTime (no TZ)" prop_read_show_UTC_no_TZ
, nameTest "UniversalTime" (prop_read_show :: UniversalTime -> Result) , nameTest "UniversalTime" (prop_read_show :: UniversalTime -> Result)
, nameTest "NominalDiffTime" (prop_read_show :: NominalDiffTime -> Result) , nameTest "NominalDiffTime" (prop_read_show :: NominalDiffTime -> Result)
, nameTest "DiffTime" (prop_read_show :: DiffTime -> Result) , nameTest "DiffTime" (prop_read_show :: DiffTime -> Result)
--nameTest "CalendarDiffDays" (prop_read_show :: CalendarDiffDays -> Result), -- nameTest "CalendarDiffDays" (prop_read_show :: CalendarDiffDays -> Result),
--nameTest "CalendarDiffTime" (prop_read_show :: CalendarDiffTime -> Result) -- nameTest "CalendarDiffTime" (prop_read_show :: CalendarDiffTime -> Result)
] ]
parseShowTests :: TestTree parseShowTests :: TestTree
......
...@@ -2,16 +2,16 @@ module Test.LocalTime.CalendarDiffTime ( ...@@ -2,16 +2,16 @@ module Test.LocalTime.CalendarDiffTime (
testCalendarDiffTime, testCalendarDiffTime,
) where ) where
--import Data.Time.LocalTime -- import Data.Time.LocalTime
import Test.Arbitrary () import Test.Arbitrary ()
import Test.Tasty import Test.Tasty
--import Test.Tasty.QuickCheck hiding (reason) -- import Test.Tasty.QuickCheck hiding (reason)
--testReadShow :: TestTree -- testReadShow :: TestTree
--testReadShow = testProperty "read . show" $ \(t :: CalendarDiffTime) -> read (show t) == t -- testReadShow = testProperty "read . show" $ \(t :: CalendarDiffTime) -> read (show t) == t
testCalendarDiffTime :: TestTree testCalendarDiffTime :: TestTree
testCalendarDiffTime = testCalendarDiffTime =
testGroup testGroup
"CalendarDiffTime" "CalendarDiffTime"
--testReadShow -- testReadShow
[] []
...@@ -10,16 +10,16 @@ import Test.Tasty ...@@ -10,16 +10,16 @@ import Test.Tasty
import Test.Tasty.HUnit import Test.Tasty.HUnit
showCal :: Integer -> String showCal :: Integer -> String
showCal mjd = showCal mjd = let
let date = ModifiedJulianDay mjd date = ModifiedJulianDay mjd
(y, m, d) = toGregorian date (y, m, d) = toGregorian date
date' = fromGregorian y m d date' = fromGregorian y m d
in concat in concat
[ show mjd ++ "=" ++ showGregorian date ++ "=" ++ showOrdinalDate date ++ "=" ++ showWeekDate date ++ "\n" [ show mjd ++ "=" ++ showGregorian date ++ "=" ++ showOrdinalDate date ++ "=" ++ showWeekDate date ++ "\n"
, if date == date' , if date == date'
then "" then ""
else "=" ++ (show $ toModifiedJulianDay date') ++ "!" else "=" ++ (show $ toModifiedJulianDay date') ++ "!"
] ]
testCal :: String testCal :: String
testCal = testCal =
...@@ -63,10 +63,10 @@ leapSec1998 :: UTCTime ...@@ -63,10 +63,10 @@ leapSec1998 :: UTCTime
leapSec1998 = localTimeToUTC utc leapSec1998Cal leapSec1998 = localTimeToUTC utc leapSec1998Cal
testUTC :: String testUTC :: String
testUTC = testUTC = let
let lsMineCal = utcToLocalTime myzone leapSec1998 lsMineCal = utcToLocalTime myzone leapSec1998
lsMine = localTimeToUTC myzone lsMineCal lsMine = localTimeToUTC myzone lsMineCal
in unlines [showCal 51178, show leapSec1998Cal, showUTCTime leapSec1998, show lsMineCal, showUTCTime lsMine] in unlines [showCal 51178, show leapSec1998Cal, showUTCTime leapSec1998, show lsMineCal, showUTCTime lsMine]
neglong :: Rational neglong :: Rational
neglong = -120 neglong = -120
...@@ -86,15 +86,15 @@ testUT1 = ...@@ -86,15 +86,15 @@ testUT1 =
] ]
testTimeOfDayToDayFraction :: String testTimeOfDayToDayFraction :: String
testTimeOfDayToDayFraction = testTimeOfDayToDayFraction = let
let f = dayFractionToTimeOfDay . timeOfDayToDayFraction f = dayFractionToTimeOfDay . timeOfDayToDayFraction
in unlines in unlines
[ show $ f $ TimeOfDay 12 34 56.789 [ show $ f $ TimeOfDay 12 34 56.789
, show $ f $ TimeOfDay 12 34 56.789123 , show $ f $ TimeOfDay 12 34 56.789123
, show $ f $ TimeOfDay 12 34 56.789123456 , show $ f $ TimeOfDay 12 34 56.789123456
, show $ f $ TimeOfDay 12 34 56.789123456789 , show $ f $ TimeOfDay 12 34 56.789123456789
, show $ f $ TimeOfDay minBound 0 0 , show $ f $ TimeOfDay minBound 0 0
] ]
testTime :: TestTree testTime :: TestTree
testTime = testTime =
......
...@@ -11,12 +11,12 @@ testTimeOfDay :: TestTree ...@@ -11,12 +11,12 @@ testTimeOfDay :: TestTree
testTimeOfDay = testTimeOfDay =
testGroup testGroup
"TimeOfDay" "TimeOfDay"
[ testProperty "daysAndTimeOfDayToTime . timeToDaysAndTimeOfDay" $ \ndt -> [ testProperty "daysAndTimeOfDayToTime . timeToDaysAndTimeOfDay" $ \ndt -> let
let (d, tod) = timeToDaysAndTimeOfDay ndt (d, tod) = timeToDaysAndTimeOfDay ndt
ndt' = daysAndTimeOfDayToTime d tod ndt' = daysAndTimeOfDayToTime d tod
in ndt' == ndt in ndt' == ndt
, testProperty "timeOfDayToTime . timeToTimeOfDay" $ \dt -> , testProperty "timeOfDayToTime . timeToTimeOfDay" $ \dt -> let
let tod = timeToTimeOfDay dt tod = timeToTimeOfDay dt
dt' = timeOfDayToTime tod dt' = timeOfDayToTime tod
in dt' == dt in dt' == dt
] ]
...@@ -76,19 +76,20 @@ locale :: TimeLocale ...@@ -76,19 +76,20 @@ locale :: TimeLocale
locale = defaultTimeLocale{dateTimeFmt = "%a %b %e %H:%M:%S %Y"} locale = defaultTimeLocale{dateTimeFmt = "%a %b %e %H:%M:%S %Y"}
instance Random (F.Fixed res) where instance Random (F.Fixed res) where
randomR (MkFixed lo, MkFixed hi) oldgen = randomR (MkFixed lo, MkFixed hi) oldgen = let
let (v, newgen) = randomR (lo, hi) oldgen (v, newgen) = randomR (lo, hi) oldgen
in (MkFixed v, newgen) in (MkFixed v, newgen)
random oldgen = random oldgen = let
let (v, newgen) = random oldgen (v, newgen) = random oldgen
in (MkFixed v, newgen) in (MkFixed v, newgen)
instance Arbitrary TimeZone where instance Arbitrary TimeZone where
arbitrary = do arbitrary = do
mins <- choose (-2000, 2000) mins <- choose (-2000, 2000)
dst <- arbitrary dst <- arbitrary
hasName <- arbitrary hasName <- arbitrary
let name = let
name =
if hasName if hasName
then "ZONE" then "ZONE"
else "" else ""
...@@ -103,16 +104,17 @@ instance Arbitrary TimeOfDay where ...@@ -103,16 +104,17 @@ instance Arbitrary TimeOfDay where
-- | The size of 'CTime' is platform-dependent. -- | The size of 'CTime' is platform-dependent.
secondsFitInCTime :: Integer -> Bool secondsFitInCTime :: Integer -> Bool
secondsFitInCTime sec = secondsFitInCTime sec = let
let CTime ct = fromInteger sec CTime ct = fromInteger sec
sec' = toInteger ct sec' = toInteger ct
in sec == sec' in sec == sec'
instance Arbitrary UTCTime where instance Arbitrary UTCTime where
arbitrary = do arbitrary = do
day <- choose (-25000, 75000) day <- choose (-25000, 75000)
time <- arbitrary time <- arbitrary
let -- verify that the created time can fit in the local CTime let
-- verify that the created time can fit in the local CTime
localT = LocalTime (ModifiedJulianDay day) time localT = LocalTime (ModifiedJulianDay day) time
utcT = localTimeToUTC utc localT utcT = localTimeToUTC utc localT
secondsInteger = floor (utcTimeToPOSIXSeconds utcT) secondsInteger = floor (utcTimeToPOSIXSeconds utcT)
...@@ -145,12 +147,12 @@ unixWorkarounds _ s = s ...@@ -145,12 +147,12 @@ unixWorkarounds _ s = s
compareFormat :: (String -> String) -> String -> TimeZone -> UTCTime -> Result compareFormat :: (String -> String) -> String -> TimeZone -> UTCTime -> Result
compareFormat _modUnix fmt zone _time compareFormat _modUnix fmt zone _time
| last fmt == 'Z' && timeZoneName zone == "" = rejected | last fmt == 'Z' && timeZoneName zone == "" = rejected
compareFormat modUnix fmt zone time = compareFormat modUnix fmt zone time = let
let ctime = utcToZonedTime zone time ctime = utcToZonedTime zone time
haskellText = formatTime locale fmt ctime haskellText = formatTime locale fmt ctime
unixText = unixFormatTime fmt zone time unixText = unixFormatTime fmt zone time
expectedText = unixWorkarounds fmt (modUnix unixText) expectedText = unixWorkarounds fmt (modUnix unixText)
in assertEqualQC (show time ++ " with " ++ show zone) expectedText haskellText in assertEqualQC (show time ++ " with " ++ show zone) expectedText haskellText
-- as found in http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html -- as found in http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html
-- plus FgGklz -- plus FgGklz
...@@ -198,10 +200,10 @@ testCompareHashFormat = ...@@ -198,10 +200,10 @@ testCompareHashFormat =
formatUnitTest :: String -> Pico -> String -> TestTree formatUnitTest :: String -> Pico -> String -> TestTree
formatUnitTest fmt sec expected = formatUnitTest fmt sec expected =
nameTest (show fmt) $ nameTest (show fmt) $ let
let tod = TimeOfDay 0 0 (1 + sec) tod = TimeOfDay 0 0 (1 + sec)
found = formatTime locale fmt tod found = formatTime locale fmt tod
in assertEqual "" expected found in assertEqual "" expected found
testQs :: [TestTree] testQs :: [TestTree]
testQs = testQs =
......
cabal-version: 3.0 cabal-version: 3.0
name: time name: time
version: 1.12.1 version: 1.12.2
stability: stable stability: stable
license: BSD-2-Clause license: BSD-2-Clause
license-file: LICENSE license-file: LICENSE
...@@ -13,9 +13,9 @@ description: Time, clocks and calendars ...@@ -13,9 +13,9 @@ description: Time, clocks and calendars
category: Time category: Time
build-type: Configure build-type: Configure
tested-with: tested-with:
GHC == 8.8.4,
GHC == 8.10.7, GHC == 8.10.7,
GHC == 9.0.1 GHC == 9.0.2,
GHC == 9.2.2
x-follows-version-policy: x-follows-version-policy:
extra-source-files: extra-source-files:
...@@ -49,7 +49,7 @@ library ...@@ -49,7 +49,7 @@ library
ghc-options: -Wall -fwarn-tabs ghc-options: -Wall -fwarn-tabs
c-sources: lib/cbits/HsTime.c c-sources: lib/cbits/HsTime.c
build-depends: build-depends:
base >= 4.13 && < 5, base >= 4.14 && < 5,
deepseq >= 1.1 deepseq >= 1.1
if os(windows) if os(windows)
build-depends: Win32 build-depends: Win32
...@@ -122,6 +122,16 @@ test-suite ShowDefaultTZAbbreviations ...@@ -122,6 +122,16 @@ test-suite ShowDefaultTZAbbreviations
time time
main-is: ShowDefaultTZAbbreviations.hs main-is: ShowDefaultTZAbbreviations.hs
test-suite ShowTime
type: exitcode-stdio-1.0
hs-source-dirs: test
default-language: Haskell2010
ghc-options: -Wall -fwarn-tabs
build-depends:
base,
time
main-is: ShowTime.hs
test-suite test-main test-suite test-main
type: exitcode-stdio-1.0 type: exitcode-stdio-1.0
hs-source-dirs: test/main hs-source-dirs: test/main
......