@@ -19,19 +19,18 @@ module Data.Intl.DateTimeFormat.Types
20import Data.Foreign (F, Foreign, ForeignError(..), fail, readString)
20import Data.Foreign (F, Foreign, ForeignError(..), fail, readString)
21import Data.Foreign.Index ((!))
21import Data.Foreign.Index ((!))
22+import Data.Generic (class Generic)
22−import Data.Intl.DateTimeFormat.Class (class FormatComponent, FormatComponentRecord(..), defaultComponentRecord)
23+import Data.Intl.DateTimeFormat.Class (class FormatComponent)
24+import Data.Intl.DateTimeFormat.Generic (genericFormatComponent)
23−import Data.Maybe (Maybe(..))
25+import Data.Maybe (Maybe)
24−import Data.Newtype (class Newtype, over)
26+import Data.Newtype (class Newtype)
25−import Prelude (class Eq, class Show, bind, pure, show, ($), (<>), (>>=))
27+import Prelude (class Show, bind, pure, ($), (<>), (>>=))
27foreign import data Undefined :: Type
29foreign import data Undefined :: Type
29foreign import undefined :: Undefined
30foreign import undefined :: Undefined
31data StringRep = Narrow | Short | Long
32data StringRep = Narrow | Short | Long
33−derive instance eqStringRep :: Eq StringRep
35instance showStringRep :: Show StringRep where
34instance showStringRep :: Show StringRep where
36 show Narrow = "narrow"
35 show Narrow = "narrow"
37 show Short = "short"
36 show Short = "short"
@@ -39,16 +38,12 @@ instance showStringRep :: Show StringRep where
40data NumericRep = Numeric | TwoDigit
39data NumericRep = Numeric | TwoDigit
42−derive instance eqNumericRep :: Eq NumericRep
44instance showNumericRep :: Show NumericRep where
41instance showNumericRep :: Show NumericRep where
45 show Numeric = "numeric"
42 show Numeric = "numeric"
46 show TwoDigit = "2-digit"
43 show TwoDigit = "2-digit"
48data MonthRep = MonthNumeric | MonthTwoDigit | MonthNarrow | MonthShort | MonthLong
45data MonthRep = MonthNumeric | MonthTwoDigit | MonthNarrow | MonthShort | MonthLong
50−derive instance eqMonthRep :: Eq MonthRep
52instance showMonthRep :: Show MonthRep where
47instance showMonthRep :: Show MonthRep where
53 show MonthNumeric = "numeric"
48 show MonthNumeric = "numeric"
54 show MonthTwoDigit = "2-digit"
49 show MonthTwoDigit = "2-digit"
@@ -58,8 +53,6 @@ instance showMonthRep :: Show MonthRep where
59data TimeZoneNameRep = TimeZoneNameShort | TimeZoneNameLong
54data TimeZoneNameRep = TimeZoneNameShort | TimeZoneNameLong
61−derive instance eqTimeZoneNameRep :: Eq TimeZoneNameRep
63instance showTimeZoneRep :: Show TimeZoneNameRep where
56instance showTimeZoneRep :: Show TimeZoneNameRep where
64 show TimeZoneNameShort = "short"
57 show TimeZoneNameShort = "short"
65 show TimeZoneNameLong = "long"
58 show TimeZoneNameLong = "long"
@@ -75,8 +68,6 @@ data FormatParts
75 | DayPeriod String
68 | DayPeriod String
76 | Literal String
69 | Literal String
78−derive instance eqFormatParts :: Eq FormatParts
80readFormatParts :: Foreign -> F FormatParts
71readFormatParts :: Foreign -> F FormatParts
81readFormatParts val = do
72readFormatParts val = do
82 type_ <- val ! "type" >>= readString
73 type_ <- val ! "type" >>= readString
@@ -111,8 +102,6 @@ newtype ResolvedOptions = ResolvedOptions
112derive instance newtypeResolvedOptions :: Newtype ResolvedOptions _
103derive instance newtypeResolvedOptions :: Newtype ResolvedOptions _
114−derive instance eqResolvedOptions :: Eq ResolvedOptions
116newtype WeekdayYearMonthDayHourMinuteSecond = WeekdayYearMonthDayHourMinuteSecond
105newtype WeekdayYearMonthDayHourMinuteSecond = WeekdayYearMonthDayHourMinuteSecond
117 { weekday :: StringRep
106 { weekday :: StringRep
118 , year :: NumericRep
107 , year :: NumericRep
@@ -123,21 +112,10 @@ newtype WeekdayYearMonthDayHourMinuteSecond = WeekdayYearMonthDayHourMinuteSecon
123 , second :: NumericRep
112 , second :: NumericRep
126−derive instance newtypeWeekdayYearMonthDayHourMinuteSecond :: Newtype WeekdayYearMonthDayHourMinuteSecond _
115+derive instance genericWeekdayYearMonthDayHourMinuteSecond :: Generic WeekdayYearMonthDayHourMinuteSecond _
128−derive instance eqWeekdayYearMonthDayHourMinuteSecond :: Eq WeekdayYearMonthDayHourMinuteSecond
130instance formatComponentWeekdayYearMonthDayHourMinuteSecond :: FormatComponent WeekdayYearMonthDayHourMinuteSecond where
117instance formatComponentWeekdayYearMonthDayHourMinuteSecond :: FormatComponent WeekdayYearMonthDayHourMinuteSecond where
131− formatComponent (WeekdayYearMonthDayHourMinuteSecond { weekday, year, month, day, hour, minute, second }) = over FormatComponentRecord
118+ formatComponent = genericFormatComponent
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)
140− ) defaultComponentRecord
142newtype WeekdayYearMonthDay = WeekdayYearMonthDay
120newtype WeekdayYearMonthDay = WeekdayYearMonthDay
143 { weekday :: StringRep
121 { weekday :: StringRep
@@ -146,19 +124,10 @@ newtype WeekdayYearMonthDay = WeekdayYearMonthDay
146 , day :: NumericRep
124 , day :: NumericRep
149−derive instance newtypeWeekdayYearMonthDay :: Newtype WeekdayYearMonthDay _
127+derive instance genericWeekdayYearMonthDay :: Generic WeekdayYearMonthDay _
151−derive instance eqWeekdayYearMonthDay :: Eq WeekdayYearMonthDay
153instance formatComponentWeekdayYearMonthDay :: FormatComponent WeekdayYearMonthDay where
129instance formatComponentWeekdayYearMonthDay :: FormatComponent WeekdayYearMonthDay where
154− formatComponent (WeekdayYearMonthDay { weekday, year, month, day }) = over FormatComponentRecord
130+ formatComponent = genericFormatComponent
155− (\r -> r { weekday = Just (show weekday)
156− , year = Just (show year)
157− , month = Just (show month)
158− , day = Just (show day)
160− ) defaultComponentRecord
163newtype YearMonthDay = YearMonthDay
132newtype YearMonthDay = YearMonthDay
164 { year :: NumericRep
133 { year :: NumericRep
@@ -166,50 +135,30 @@ newtype YearMonthDay = YearMonthDay
166 , day :: NumericRep
135 , day :: NumericRep
169−derive instance newtypeYearMonthDay :: Newtype YearMonthDay _
138+derive instance genericYearMonthDay :: Generic YearMonthDay _
171−derive instance eqYearMonthDay :: Eq YearMonthDay
173instance formatComponentYearMonthDay :: FormatComponent YearMonthDay where
140instance formatComponentYearMonthDay :: FormatComponent YearMonthDay where
174− formatComponent (YearMonthDay { year, month, day }) = over FormatComponentRecord
141+ formatComponent = genericFormatComponent
175− (\r -> r { year = Just (show year)
176− , month = Just (show month)
177− , day = Just (show day)
179− ) defaultComponentRecord
182newtype YearMonth = YearMonth
143newtype YearMonth = YearMonth
183 { year :: NumericRep
144 { year :: NumericRep
184 , month :: MonthRep
145 , month :: MonthRep
187−derive instance newtypeYearMonth :: Newtype YearMonth _
148+derive instance genericYearMonth :: Generic YearMonth _
189−derive instance eqYearMonth :: Eq YearMonth
191instance formatComponentYearMonth :: FormatComponent YearMonth where
150instance formatComponentYearMonth :: FormatComponent YearMonth where
192− formatComponent (YearMonth { year, month }) = over FormatComponentRecord
151+ formatComponent = genericFormatComponent
193− (\r -> r { year = Just (show year)
194− , month = Just (show month)
196− ) defaultComponentRecord
198newtype MonthDay = MonthDay
153newtype MonthDay = MonthDay
199 { month :: MonthRep
154 { month :: MonthRep
200 , day :: NumericRep
155 , day :: NumericRep
203−derive instance newtypeMonthDay :: Newtype MonthDay _
158+derive instance genericMonthDay :: Generic MonthDay _
205−derive instance eqMonthDay :: Eq MonthDay
207instance formatComponentMonthDay :: FormatComponent MonthDay where
160instance formatComponentMonthDay :: FormatComponent MonthDay where
208− formatComponent (MonthDay { month, day }) = over FormatComponentRecord
161+ formatComponent = genericFormatComponent
209− (\r -> r { month = Just (show month)
210− , day = Just (show day)
212− ) defaultComponentRecord
214newtype HourMinuteSecond = HourMinuteSecond
163newtype HourMinuteSecond = HourMinuteSecond
215 { hour :: NumericRep
164 { hour :: NumericRep
@@ -217,30 +166,17 @@ newtype HourMinuteSecond = HourMinuteSecond
217 , second :: NumericRep
166 , second :: NumericRep
220−derive instance newtypeHourMinuteSecond :: Newtype HourMinuteSecond _
169+derive instance genericHourMinuteSecond :: Generic HourMinuteSecond _
222−derive instance eqHourMinuteSecond :: Eq HourMinuteSecond
224instance formatComponentHourMinuteSecond :: FormatComponent HourMinuteSecond where
171instance formatComponentHourMinuteSecond :: FormatComponent HourMinuteSecond where
225− formatComponent (HourMinuteSecond { hour, minute, second }) = over FormatComponentRecord
172+ formatComponent = genericFormatComponent
226− (\r -> r { hour = Just (show hour)
227− , minute = Just (show minute)
228− , second = Just (show second)
230− ) defaultComponentRecord
232newtype HourMinute = HourMinute
174newtype HourMinute = HourMinute
233 { hour :: NumericRep
175 { hour :: NumericRep
234 , minute :: NumericRep
176 , minute :: NumericRep
237−derive instance newtypeHourMinute :: Newtype HourMinute _
179+derive instance genericHourMinute :: Generic HourMinute _
239−derive instance eqHourMinute :: Eq HourMinute
241instance formatComponentHourMinute :: FormatComponent HourMinute where
181instance formatComponentHourMinute :: FormatComponent HourMinute where
242− formatComponent (HourMinute { hour, minute }) = over FormatComponentRecord
182+ formatComponent = genericFormatComponent
243− (\r -> r { hour = Just (show hour)
244− , minute = Just (show minute)
246− ) defaultComponentRecord