@@ -19,12 +19,10 @@ 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 Show, bind, pure, show, ($), (<>), (>>=))
2826
2927foreign import data Undefined :: Type
3028foreign import undefined :: Undefined
@@ -112,10 +110,17 @@ newtype WeekdayYearMonthDayHourMinuteSecond = WeekdayYearMonthDayHourMinuteSecon
112110 , second :: NumericRep
113111 }
114112
115−derive instance genericWeekdayYearMonthDayHourMinuteSecond :: Generic WeekdayYearMonthDayHourMinuteSecond _
116−
117113instance formatComponentWeekdayYearMonthDayHourMinuteSecond :: FormatComponent WeekdayYearMonthDayHourMinuteSecond where
118− formatComponent = genericFormatComponent
114+ formatComponent (WeekdayYearMonthDayHourMinuteSecond { weekday, year, month, day, hour, minute, second }) = over FormatComponentRecord
115+ (\r -> r { weekday = Just (show weekday)
116+ , year = Just (show year)
117+ , month = Just (show month)
118+ , day = Just (show day)
119+ , hour = Just (show hour)
120+ , minute = Just (show minute)
121+ , second = Just (show second)
122+ }
123+ ) defaultComponentRecord
119124
120125newtype WeekdayYearMonthDay = WeekdayYearMonthDay
121126 { weekday :: StringRep
@@ -124,10 +129,15 @@ newtype WeekdayYearMonthDay = WeekdayYearMonthDay
124129 , day :: NumericRep
125130 }
126131
127−derive instance genericWeekdayYearMonthDay :: Generic WeekdayYearMonthDay _
128−
129132instance formatComponentWeekdayYearMonthDay :: FormatComponent WeekdayYearMonthDay where
130− formatComponent = genericFormatComponent
133+ formatComponent (WeekdayYearMonthDay { weekday, year, month, day }) = over FormatComponentRecord
134+ (\r -> r { weekday = Just (show weekday)
135+ , year = Just (show year)
136+ , month = Just (show month)
137+ , day = Just (show day)
138+ }
139+ ) defaultComponentRecord
140+
131141
132142newtype YearMonthDay = YearMonthDay
133143 { year :: NumericRep
@@ -135,30 +145,38 @@ newtype YearMonthDay = YearMonthDay
135145 , day :: NumericRep
136146 }
137147
138−derive instance genericYearMonthDay :: Generic YearMonthDay _
139−
140148instance formatComponentYearMonthDay :: FormatComponent YearMonthDay where
141− formatComponent = genericFormatComponent
149+ formatComponent (YearMonthDay { year, month, day }) = over FormatComponentRecord
150+ (\r -> r { year = Just (show year)
151+ , month = Just (show month)
152+ , day = Just (show day)
153+ }
154+ ) defaultComponentRecord
155+
142156
143157newtype YearMonth = YearMonth
144158 { year :: NumericRep
145159 , month :: MonthRep
146160 }
147161
148−derive instance genericYearMonth :: Generic YearMonth _
149−
150162instance formatComponentYearMonth :: FormatComponent YearMonth where
151− formatComponent = genericFormatComponent
163+ formatComponent (YearMonth { year, month }) = over FormatComponentRecord
164+ (\r -> r { year = Just (show year)
165+ , month = Just (show month)
166+ }
167+ ) defaultComponentRecord
152168
153169newtype MonthDay = MonthDay
154170 { month :: MonthRep
155171 , day :: NumericRep
156172 }
157173
158−derive instance genericMonthDay :: Generic MonthDay _
159−
160174instance formatComponentMonthDay :: FormatComponent MonthDay where
161− formatComponent = genericFormatComponent
175+ formatComponent (MonthDay { month, day }) = over FormatComponentRecord
176+ (\r -> r { month = Just (show month)
177+ , day = Just (show day)
178+ }
179+ ) defaultComponentRecord
162180
163181newtype HourMinuteSecond = HourMinuteSecond
164182 { hour :: NumericRep
@@ -166,17 +184,22 @@ newtype HourMinuteSecond = HourMinuteSecond
166184 , second :: NumericRep
167185 }
168186
169−derive instance genericHourMinuteSecond :: Generic HourMinuteSecond _
170−
171187instance formatComponentHourMinuteSecond :: FormatComponent HourMinuteSecond where
172− formatComponent = genericFormatComponent
188+ formatComponent (HourMinuteSecond { hour, minute, second }) = over FormatComponentRecord
189+ (\r -> r { hour = Just (show hour)
190+ , minute = Just (show minute)
191+ , second = Just (show second)
192+ }
193+ ) defaultComponentRecord
173194
174195newtype HourMinute = HourMinute
175196 { hour :: NumericRep
176197 , minute :: NumericRep
177198 }
178199
179−derive instance genericHourMinute :: Generic HourMinute _
180−
181200instance formatComponentHourMinute :: FormatComponent HourMinute where
182− formatComponent = genericFormatComponent
201+ formatComponent (HourMinute { hour, minute }) = over FormatComponentRecord
202+ (\r -> r { hour = Just (show hour)
203+ , minute = Just (show minute)
204+ }
205+ ) defaultComponentRecord