@@ -19,18 +19,19 @@ module Data.Intl.DateTimeFormat.Types
1919
2020import Data.Foreign (F, Foreign, ForeignError(..), fail, readString)
2121import Data.Foreign.Index ((!))
22−import Data.Generic (class Generic)
23−import Data.Intl.DateTimeFormat.Class (class FormatComponent)
24−import Data.Intl.DateTimeFormat.Generic (genericFormatComponent)
25−import Data.Maybe (Maybe)
26−import Data.Newtype (class Newtype)
27−import Prelude (class Show, bind, pure, ($), (<>), (>>=))
22+import Data.Intl.DateTimeFormat.Class (class FormatComponent, FormatComponentRecord(..), defaultComponentRecord)
23+import Data.Maybe (Maybe(..))
24+import Data.Newtype (class Newtype, over)
25+import Prelude (class Eq, class Show, bind, pure, show, ($), (<>), (>>=))
2826
2927foreign import data Undefined :: Type
28+
3029foreign import undefined :: Undefined
3130
3231data StringRep = Narrow | Short | Long
3332
33+derive instance eqStringRep :: Eq StringRep
34+
3435instance showStringRep :: Show StringRep where
3536 show Narrow = "narrow"
3637 show Short = "short"
@@ -38,12 +39,16 @@ instance showStringRep :: Show StringRep where
3839
3940data NumericRep = Numeric | TwoDigit
4041
42+derive instance eqNumericRep :: Eq NumericRep
43+
4144instance showNumericRep :: Show NumericRep where
4245 show Numeric = "numeric"
4346 show TwoDigit = "2-digit"
4447
4548data MonthRep = MonthNumeric | MonthTwoDigit | MonthNarrow | MonthShort | MonthLong
4649
50+derive instance eqMonthRep :: Eq MonthRep
51+
4752instance showMonthRep :: Show MonthRep where
4853 show MonthNumeric = "numeric"
4954 show MonthTwoDigit = "2-digit"
@@ -53,6 +58,8 @@ instance showMonthRep :: Show MonthRep where
5358
5459data TimeZoneNameRep = TimeZoneNameShort | TimeZoneNameLong
5560
61+derive instance eqTimeZoneNameRep :: Eq TimeZoneNameRep
62+
5663instance showTimeZoneRep :: Show TimeZoneNameRep where
5764 show TimeZoneNameShort = "short"
5865 show TimeZoneNameLong = "long"
@@ -68,6 +75,8 @@ data FormatParts
6875 | DayPeriod String
6976 | Literal String
7077
78+derive instance eqFormatParts :: Eq FormatParts
79+
7180readFormatParts :: Foreign -> F FormatParts
7281readFormatParts val = do
7382 type_ <- val ! "type" >>= readString
@@ -102,6 +111,8 @@ newtype ResolvedOptions = ResolvedOptions
102111
103112derive instance newtypeResolvedOptions :: Newtype ResolvedOptions _
104113
114+derive instance eqResolvedOptions :: Eq ResolvedOptions
115+
105116newtype WeekdayYearMonthDayHourMinuteSecond = WeekdayYearMonthDayHourMinuteSecond
106117 { weekday :: StringRep
107118 , year :: NumericRep
@@ -112,10 +123,21 @@ newtype WeekdayYearMonthDayHourMinuteSecond = WeekdayYearMonthDayHourMinuteSecon
112123 , second :: NumericRep
113124 }
114125
115−derive instance genericWeekdayYearMonthDayHourMinuteSecond :: Generic WeekdayYearMonthDayHourMinuteSecond _
126+derive instance newtypeWeekdayYearMonthDayHourMinuteSecond :: Newtype WeekdayYearMonthDayHourMinuteSecond _
127+
128+derive instance eqWeekdayYearMonthDayHourMinuteSecond :: Eq WeekdayYearMonthDayHourMinuteSecond
116129
117130instance formatComponentWeekdayYearMonthDayHourMinuteSecond :: FormatComponent WeekdayYearMonthDayHourMinuteSecond where
118− formatComponent = genericFormatComponent
131+ formatComponent (WeekdayYearMonthDayHourMinuteSecond { weekday, year, month, day, hour, minute, second }) = over FormatComponentRecord
132+ (\r -> r { weekday = Just (show weekday)
133+ , year = Just (show year)
134+ , month = Just (show month)
135+ , day = Just (show day)
136+ , hour = Just (show hour)
137+ , minute = Just (show minute)
138+ , second = Just (show second)
139+ }
140+ ) defaultComponentRecord
119141
120142newtype WeekdayYearMonthDay = WeekdayYearMonthDay
121143 { weekday :: StringRep
@@ -124,10 +146,19 @@ newtype WeekdayYearMonthDay = WeekdayYearMonthDay
124146 , day :: NumericRep
125147 }
126148
127−derive instance genericWeekdayYearMonthDay :: Generic WeekdayYearMonthDay _
149+derive instance newtypeWeekdayYearMonthDay :: Newtype WeekdayYearMonthDay _
150+
151+derive instance eqWeekdayYearMonthDay :: Eq WeekdayYearMonthDay
128152
129153instance formatComponentWeekdayYearMonthDay :: FormatComponent WeekdayYearMonthDay where
130− formatComponent = genericFormatComponent
154+ formatComponent (WeekdayYearMonthDay { weekday, year, month, day }) = over FormatComponentRecord
155+ (\r -> r { weekday = Just (show weekday)
156+ , year = Just (show year)
157+ , month = Just (show month)
158+ , day = Just (show day)
159+ }
160+ ) defaultComponentRecord
161+
131162
132163newtype YearMonthDay = YearMonthDay
133164 { year :: NumericRep
@@ -135,30 +166,50 @@ newtype YearMonthDay = YearMonthDay
135166 , day :: NumericRep
136167 }
137168
138−derive instance genericYearMonthDay :: Generic YearMonthDay _
169+derive instance newtypeYearMonthDay :: Newtype YearMonthDay _
170+
171+derive instance eqYearMonthDay :: Eq YearMonthDay
139172
140173instance formatComponentYearMonthDay :: FormatComponent YearMonthDay where
141− formatComponent = genericFormatComponent
174+ formatComponent (YearMonthDay { year, month, day }) = over FormatComponentRecord
175+ (\r -> r { year = Just (show year)
176+ , month = Just (show month)
177+ , day = Just (show day)
178+ }
179+ ) defaultComponentRecord
180+
142181
143182newtype YearMonth = YearMonth
144183 { year :: NumericRep
145184 , month :: MonthRep
146185 }
147186
148−derive instance genericYearMonth :: Generic YearMonth _
187+derive instance newtypeYearMonth :: Newtype YearMonth _
188+
189+derive instance eqYearMonth :: Eq YearMonth
149190
150191instance formatComponentYearMonth :: FormatComponent YearMonth where
151− formatComponent = genericFormatComponent
192+ formatComponent (YearMonth { year, month }) = over FormatComponentRecord
193+ (\r -> r { year = Just (show year)
194+ , month = Just (show month)
195+ }
196+ ) defaultComponentRecord
152197
153198newtype MonthDay = MonthDay
154199 { month :: MonthRep
155200 , day :: NumericRep
156201 }
157202
158−derive instance genericMonthDay :: Generic MonthDay _
203+derive instance newtypeMonthDay :: Newtype MonthDay _
204+
205+derive instance eqMonthDay :: Eq MonthDay
159206
160207instance formatComponentMonthDay :: FormatComponent MonthDay where
161− formatComponent = genericFormatComponent
208+ formatComponent (MonthDay { month, day }) = over FormatComponentRecord
209+ (\r -> r { month = Just (show month)
210+ , day = Just (show day)
211+ }
212+ ) defaultComponentRecord
162213
163214newtype HourMinuteSecond = HourMinuteSecond
164215 { hour :: NumericRep
@@ -166,17 +217,30 @@ newtype HourMinuteSecond = HourMinuteSecond
166217 , second :: NumericRep
167218 }
168219
169−derive instance genericHourMinuteSecond :: Generic HourMinuteSecond _
220+derive instance newtypeHourMinuteSecond :: Newtype HourMinuteSecond _
221+
222+derive instance eqHourMinuteSecond :: Eq HourMinuteSecond
170223
171224instance formatComponentHourMinuteSecond :: FormatComponent HourMinuteSecond where
172− formatComponent = genericFormatComponent
225+ formatComponent (HourMinuteSecond { hour, minute, second }) = over FormatComponentRecord
226+ (\r -> r { hour = Just (show hour)
227+ , minute = Just (show minute)
228+ , second = Just (show second)
229+ }
230+ ) defaultComponentRecord
173231
174232newtype HourMinute = HourMinute
175233 { hour :: NumericRep
176234 , minute :: NumericRep
177235 }
178236
179−derive instance genericHourMinute :: Generic HourMinute _
237+derive instance newtypeHourMinute :: Newtype HourMinute _
238+
239+derive instance eqHourMinute :: Eq HourMinute
180240
181241instance formatComponentHourMinute :: FormatComponent HourMinute where
182− formatComponent = genericFormatComponent
242+ formatComponent (HourMinute { hour, minute }) = over FormatComponentRecord
243+ (\r -> r { hour = Just (show hour)
244+ , minute = Just (show minute)
245+ }
246+ ) defaultComponentRecord