@@ -19,19 +19,18 @@ module Data.Intl.DateTimeFormat.Types
1919
2020import Data.Foreign (F, Foreign, ForeignError(..), fail, readString)
2121import Data.Foreign.Index ((!))
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, ($), (<>), (>>=))
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, ($), (<>), (>>=))
2628
2729foreign import data Undefined :: Type
28−
2930foreign import undefined :: Undefined
3031
3132data StringRep = Narrow | Short | Long
3233
33−derive instance eqStringRep :: Eq StringRep
34−
3534instance showStringRep :: Show StringRep where
3635 show Narrow = "narrow"
3736 show Short = "short"
@@ -39,16 +38,12 @@ instance showStringRep :: Show StringRep where
3938
4039data NumericRep = Numeric | TwoDigit
4140
42−derive instance eqNumericRep :: Eq NumericRep
43−
4441instance showNumericRep :: Show NumericRep where
4542 show Numeric = "numeric"
4643 show TwoDigit = "2-digit"
4744
4845data MonthRep = MonthNumeric | MonthTwoDigit | MonthNarrow | MonthShort | MonthLong
4946
50−derive instance eqMonthRep :: Eq MonthRep
51−
5247instance showMonthRep :: Show MonthRep where
5348 show MonthNumeric = "numeric"
5449 show MonthTwoDigit = "2-digit"
@@ -58,8 +53,6 @@ instance showMonthRep :: Show MonthRep where
5853
5954data TimeZoneNameRep = TimeZoneNameShort | TimeZoneNameLong
6055
61−derive instance eqTimeZoneNameRep :: Eq TimeZoneNameRep
62−
6356instance showTimeZoneRep :: Show TimeZoneNameRep where
6457 show TimeZoneNameShort = "short"
6558 show TimeZoneNameLong = "long"
@@ -75,8 +68,6 @@ data FormatParts
7568 | DayPeriod String
7669 | Literal String
7770
78−derive instance eqFormatParts :: Eq FormatParts
79−
8071readFormatParts :: Foreign -> F FormatParts
8172readFormatParts val = do
8273 type_ <- val ! "type" >>= readString
@@ -111,8 +102,6 @@ newtype ResolvedOptions = ResolvedOptions
111102
112103derive instance newtypeResolvedOptions :: Newtype ResolvedOptions _
113104
114−derive instance eqResolvedOptions :: Eq ResolvedOptions
115−
116105newtype WeekdayYearMonthDayHourMinuteSecond = WeekdayYearMonthDayHourMinuteSecond
117106 { weekday :: StringRep
118107 , year :: NumericRep
@@ -123,21 +112,10 @@ newtype WeekdayYearMonthDayHourMinuteSecond = WeekdayYearMonthDayHourMinuteSecon
123112 , second :: NumericRep
124113 }
125114
126−derive instance newtypeWeekdayYearMonthDayHourMinuteSecond :: Newtype WeekdayYearMonthDayHourMinuteSecond _
127−
128−derive instance eqWeekdayYearMonthDayHourMinuteSecond :: Eq WeekdayYearMonthDayHourMinuteSecond
115+derive instance genericWeekdayYearMonthDayHourMinuteSecond :: Generic WeekdayYearMonthDayHourMinuteSecond _
129116
130117instance formatComponentWeekdayYearMonthDayHourMinuteSecond :: FormatComponent WeekdayYearMonthDayHourMinuteSecond where
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
118+ formatComponent = genericFormatComponent
141119
142120newtype WeekdayYearMonthDay = WeekdayYearMonthDay
143121 { weekday :: StringRep
@@ -146,19 +124,10 @@ newtype WeekdayYearMonthDay = WeekdayYearMonthDay
146124 , day :: NumericRep
147125 }
148126
149−derive instance newtypeWeekdayYearMonthDay :: Newtype WeekdayYearMonthDay _
150−
151−derive instance eqWeekdayYearMonthDay :: Eq WeekdayYearMonthDay
127+derive instance genericWeekdayYearMonthDay :: Generic WeekdayYearMonthDay _
152128
153129instance formatComponentWeekdayYearMonthDay :: FormatComponent WeekdayYearMonthDay where
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−
130+ formatComponent = genericFormatComponent
162131
163132newtype YearMonthDay = YearMonthDay
164133 { year :: NumericRep
@@ -166,50 +135,30 @@ newtype YearMonthDay = YearMonthDay
166135 , day :: NumericRep
167136 }
168137
169−derive instance newtypeYearMonthDay :: Newtype YearMonthDay _
170−
171−derive instance eqYearMonthDay :: Eq YearMonthDay
138+derive instance genericYearMonthDay :: Generic YearMonthDay _
172139
173140instance formatComponentYearMonthDay :: FormatComponent YearMonthDay where
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−
141+ formatComponent = genericFormatComponent
181142
182143newtype YearMonth = YearMonth
183144 { year :: NumericRep
184145 , month :: MonthRep
185146 }
186147
187−derive instance newtypeYearMonth :: Newtype YearMonth _
188−
189−derive instance eqYearMonth :: Eq YearMonth
148+derive instance genericYearMonth :: Generic YearMonth _
190149
191150instance formatComponentYearMonth :: FormatComponent YearMonth where
192− formatComponent (YearMonth { year, month }) = over FormatComponentRecord
193− (\r -> r { year = Just (show year)
194− , month = Just (show month)
195− }
196− ) defaultComponentRecord
151+ formatComponent = genericFormatComponent
197152
198153newtype MonthDay = MonthDay
199154 { month :: MonthRep
200155 , day :: NumericRep
201156 }
202157
203−derive instance newtypeMonthDay :: Newtype MonthDay _
204−
205−derive instance eqMonthDay :: Eq MonthDay
158+derive instance genericMonthDay :: Generic MonthDay _
206159
207160instance formatComponentMonthDay :: FormatComponent MonthDay where
208− formatComponent (MonthDay { month, day }) = over FormatComponentRecord
209− (\r -> r { month = Just (show month)
210− , day = Just (show day)
211− }
212− ) defaultComponentRecord
161+ formatComponent = genericFormatComponent
213162
214163newtype HourMinuteSecond = HourMinuteSecond
215164 { hour :: NumericRep
@@ -217,30 +166,17 @@ newtype HourMinuteSecond = HourMinuteSecond
217166 , second :: NumericRep
218167 }
219168
220−derive instance newtypeHourMinuteSecond :: Newtype HourMinuteSecond _
221−
222−derive instance eqHourMinuteSecond :: Eq HourMinuteSecond
169+derive instance genericHourMinuteSecond :: Generic HourMinuteSecond _
223170
224171instance formatComponentHourMinuteSecond :: FormatComponent HourMinuteSecond where
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
172+ formatComponent = genericFormatComponent
231173
232174newtype HourMinute = HourMinute
233175 { hour :: NumericRep
234176 , minute :: NumericRep
235177 }
236178
237−derive instance newtypeHourMinute :: Newtype HourMinute _
238−
239−derive instance eqHourMinute :: Eq HourMinute
179+derive instance genericHourMinute :: Generic HourMinute _
240180
241181instance formatComponentHourMinute :: FormatComponent HourMinute where
242− formatComponent (HourMinute { hour, minute }) = over FormatComponentRecord
243− (\r -> r { hour = Just (show hour)
244− , minute = Just (show minute)
245− }
246− ) defaultComponentRecord
182+ formatComponent = genericFormatComponent