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