1
+ {-# LANGUAGE CPP #-}
1
2
{-# OPTIONS -fno-warn-orphans #-}
2
3
3
4
module Test.Format.Format (
@@ -6,6 +7,9 @@ module Test.Format.Format (
6
7
7
8
import Data.Char
8
9
import Data.Fixed as F
10
+ #if MIN_VERSION_base(4,19,0)
11
+ import Data.List (unsnoc )
12
+ #endif
9
13
import Data.Time
10
14
import Data.Time.Clock.POSIX
11
15
import Foreign
@@ -151,16 +155,25 @@ unixWorkarounds fmt s
151
155
unixWorkarounds _ s = s
152
156
153
157
compareFormat :: (String -> String ) -> String -> TimeZone -> UTCTime -> Result
154
- compareFormat _modUnix fmt zone _time
155
- | last fmt == ' Z' && timeZoneName zone == " " = rejected
156
- compareFormat modUnix fmt zone time =
157
- let
158
- ctime = utcToZonedTime zone time
159
- haskellText = formatTime locale fmt ctime
160
- unixText = unixFormatTime fmt zone time
161
- expectedText = unixWorkarounds fmt (modUnix unixText)
162
- in
163
- assertEqualQC (show time ++ " with " ++ show zone) expectedText haskellText
158
+ compareFormat modUnix fmt zone time = case unsnoc fmt of
159
+ Nothing ->
160
+ error " compareFormat: The impossible happened! Format string is \"\" ."
161
+ Just (_, lastChar)
162
+ | lastChar == ' Z' && timeZoneName zone == " " -> rejected
163
+ | otherwise ->
164
+ let
165
+ ctime = utcToZonedTime zone time
166
+ haskellText = formatTime locale fmt ctime
167
+ unixText = unixFormatTime fmt zone time
168
+ expectedText = unixWorkarounds fmt (modUnix unixText)
169
+ in
170
+ assertEqualQC (show time ++ " with " ++ show zone) expectedText haskellText
171
+
172
+ #if !MIN_VERSION_base(4,19,0)
173
+ unsnoc :: [a ] -> Maybe ([a ], a )
174
+ unsnoc = foldr (\ x -> Just . maybe ([] , x) (\ (~ (a, b)) -> (x : a, b))) Nothing
175
+ {-# INLINABLE unsnoc #-}
176
+ #endif
164
177
165
178
-- as found in http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html
166
179
-- plus FgGklz
0 commit comments