@@ -9,7 +9,7 @@ import Data.DateTime (Date, DateTime(..), Month(..), canonicalDate)
99import Data.Either (Either(..), fromRight, isLeft)
1010import Data.Enum (toEnum)
1111import Data.Foldable (intercalate)
12−import Data.Foreign (renderForeignError)
12+import Data.Foreign (F, renderForeignError)
1313import Data.Generic.Rep (class Generic)
1414import Data.Intl.DateTimeFormat (DateTimeFormatOptions(DateTimeFormatOptions), DateTimeFormatOptions', HourMinute(HourMinute), HourMinuteSecond(HourMinuteSecond), LocalesOption, MonthDay(MonthDay), MonthRep(MonthTwoDigit, MonthNumeric, MonthNarrow, MonthShort, MonthLong), NumericRep(Numeric, TwoDigit), ResolvedOptions(..), StringRep(Short, Long), TimeZone(TimeZone), WeekdayYearMonthDay(WeekdayYearMonthDay), WeekdayYearMonthDayHourMinuteSecond(WeekdayYearMonthDayHourMinuteSecond), YearMonth(YearMonth), YearMonthDay(YearMonthDay), createDateTimeFormatter, formatJSDate, resolvedOptions, supportedLocalesOf)
1515import Data.Intl.DateTimeFormat.Generic (class FormatComponent, genericFormatComponent)
@@ -52,6 +52,9 @@ main :: Tests
5252main = do
5353 let
5454
55+ unsafeFromF :: forall a. F a -> a
56+ unsafeFromF = unsafePartial fromRight <<< runExcept
57+
5558 locales :: LocalesOption
5659 locales = inj (SProxy :: SProxy "locale") "en-US"
5760
@@ -69,7 +72,7 @@ main = do
6972 (inj (SProxy :: SProxy "hourMinute") (HourMinute {hour: TwoDigit, minute: TwoDigit}))
7073 )
7174
72− fmtHourMinute = unsafePartial $ fromRight $
75+ fmtHourMinute = unsafeFromF $
7376 createDateTimeFormatter locales opts
7477 where
7578 opts :: DateTimeFormatOptions'
@@ -83,7 +86,7 @@ main = do
8386 (inj (SProxy :: SProxy "hourMinute") (HourMinute {hour: TwoDigit, minute: TwoDigit}))
8487 )
8588
86− fmtHourMinuteSecond = unsafePartial $ fromRight $
89+ fmtHourMinuteSecond = unsafeFromF $
8790 createDateTimeFormatter locales opts
8891 where
8992 opts :: DateTimeFormatOptions'
@@ -97,7 +100,7 @@ main = do
97100 (inj (SProxy :: SProxy "hourMinuteSecond") (HourMinuteSecond {hour: Numeric, minute: Numeric, second: Numeric}))
98101 )
99102
100− fmtWeekdayYearMonthDayHourMinuteSecond = unsafePartial $ fromRight $
103+ fmtWeekdayYearMonthDayHourMinuteSecond = unsafeFromF $
101104 createDateTimeFormatter locales opts
102105 where
103106 opts :: DateTimeFormatOptions'
@@ -123,7 +126,7 @@ main = do
123126 )
124127 )
125128
126− fmtWeekdayYearMonthDay = unsafePartial $ fromRight $
129+ fmtWeekdayYearMonthDay = unsafeFromF $
127130 createDateTimeFormatter locales opts
128131 where
129132 opts :: DateTimeFormatOptions'
@@ -146,7 +149,7 @@ main = do
146149 )
147150 )
148151
149− fmtYearMonthDay = unsafePartial $ fromRight $
152+ fmtYearMonthDay = unsafeFromF $
150153 createDateTimeFormatter locales opts
151154 where
152155 opts :: DateTimeFormatOptions'
@@ -168,7 +171,7 @@ main = do
168171 )
169172 )
170173
171− fmtYearMonth = unsafePartial $ fromRight $
174+ fmtYearMonth = unsafeFromF $
172175 createDateTimeFormatter locales opts
173176 where
174177 opts :: DateTimeFormatOptions'
@@ -189,7 +192,7 @@ main = do
189192 )
190193 )
191194
192− fmtMonthDay = unsafePartial $ fromRight $
195+ fmtMonthDay = unsafeFromF $
193196 createDateTimeFormatter locales opts
194197 where
195198 opts :: DateTimeFormatOptions'
@@ -210,7 +213,7 @@ main = do
210213 )
211214 )
212215
213− fmtEraYear = unsafePartial $ fromRight $
216+ fmtEraYear = unsafeFromF $
214217 createDateTimeFormatter locales opts
215218 where
216219 opts :: DateTimeFormatOptions EraYear
@@ -231,7 +234,7 @@ main = do
231234 )
232235 )
233236
234− fmtEra = unsafePartial $ fromRight $
237+ fmtEra = unsafeFromF $
235238 createDateTimeFormatter locales opts
236239 where
237240 opts :: DateTimeFormatOptions Era
@@ -277,7 +280,7 @@ main = do
277280 Nothing -> unsafeCrashWith "jsDate not parsed"
278281 Just d -> do
279282
280− assert' "fmtError expected to return error" $ isLeft fmtError
283+ assert' "fmtError expected to return error" $ isLeft (runExcept fmtError)
281284
282285 let fmtDate1 = formatJSDate fmtWeekdayYearMonthDayHourMinuteSecond d
283286 fmtDate1Expected = "Tue, January 2, 2018, 12:00:00 PM"