git.iko.soy/purescript-intl
on 2431d46 help sign in
3 files changed+13−130
since splitsnapshots
unifiedsplit
src/Data/Intl/DateTimeFormat.purs+11−99 src/Data/Intl/DateTimeFormat/Class.purs+1−3 src/Data/Intl/DateTimeFormat/Types.purs+1−28
src/Data/Intl/DateTimeFormat.purs+11−99
@@ -1,4 +1,4 @@
1−module Data.Intl.DateTimeFormat
1+module Data.Intl.DateTimeFormat
22 ( LocalesOption
33 , LocaleMatcher(..)
44 , TimeZone(..)
@@ -120,15 +120,15 @@ formatDateTimeOptions (DateTimeFormatOptions opts comps) = merge opts' (compsCoe
120120 , hour12: fromMaybe (unsafeCoerce undefined) opts.hour12
121121 , formatMatcher: maybe undefinedString show opts.formatMatcher
122122 }
123− comps' = un FormatComponentRecord $ case_
124− # on (SProxy :: SProxy "weekdayYearMonthDayHourMinuteSecond") formatComponent
125− # on (SProxy :: SProxy "weekdayYearMonthDay") formatComponent
126− # on (SProxy :: SProxy "yearMonthDay") formatComponent
127− # on (SProxy :: SProxy "yearMonth") formatComponent
128− # on (SProxy :: SProxy "monthDay") formatComponent
129− # on (SProxy :: SProxy "hourMinuteSecond") formatComponent
130− # on (SProxy :: SProxy "hourMinute") formatComponent
131− # on (SProxy :: SProxy "custom") formatComponent
123+ comps' = case_
124+ # on (SProxy :: SProxy "weekdayYearMonthDayHourMinuteSecond") (un FormatComponentRecord <<< formatComponent)
125+ # on (SProxy :: SProxy "weekdayYearMonthDay") (un FormatComponentRecord <<< formatComponent)
126+ # on (SProxy :: SProxy "yearMonthDay") (un FormatComponentRecord <<< formatComponent)
127+ # on (SProxy :: SProxy "yearMonth") (un FormatComponentRecord <<< formatComponent)
128+ # on (SProxy :: SProxy "monthDay") (un FormatComponentRecord <<< formatComponent)
129+ # on (SProxy :: SProxy "hourMinuteSecond") (un FormatComponentRecord <<< formatComponent)
130+ # on (SProxy :: SProxy "hourMinute") (un FormatComponentRecord <<< formatComponent)
131+ # on (SProxy :: SProxy "custom") (un FormatComponentRecord <<< formatComponent)
132132 $ comps
133133
134134 toUndefined :: Maybe String -> String
@@ -196,88 +196,6 @@ foreign import createDateTimeFormatImpl
196196 DateTimeFormatOptions_
197197 (F DateTimeFormat)
198198
199−-- | Examples
200−-- | ``` purescript
201−-- | import Data.Variant (inj)
202−-- |
203−-- | fmtHourMinute = F DateTimeFormat
204−-- | fmtHourMinute = createDateTimeFormat locale opts
205−-- | where
206−-- | locale = inj (SProxy :: SProxy "locale") "en-GB"
207−-- | opts = (DateTimeFormatOptions
208−-- | { localeMatcher: Nothing
209−-- | , timeZone: (Just (TimeZone "Europe/London"))
210−-- | , hour12: Just false
211−-- | , formatMatcher: Nothing
212−-- | }
213−-- | (inj (SProxy :: SProxy "hourMinute")
214−-- | (HourMinute {hour: TwoDigit, minute: TwoDigit}))
215−-- |
216−-- |
217−-- | fmtDate :: F DateTimeFormat
218−-- | fmtDate = createDateTimeFormat locale opts
219−-- | wher
220−-- | locale = inj (SProxy :: SProxy "locale") "en-GB"
221−-- | opts :: DateTimeFormatOptions'
222−-- | opts =
223−-- | (DateTimeFormatOptions
224−-- | { localeMatcher: Nothing
225−-- | , timeZone: (Just (TimeZone "Europe/London"))
226−-- | , hour12: Just true
227−-- | , formatMatcher: Nothing
228−-- | }
229−-- | (inj
230−-- | (SProxy :: SProxy "weekdayYearMonthDayHourMinuteSecond")
231−-- | (WeekdayYearMonthDayHourMinuteSecond
232−-- | { weekday: Short
233−-- | , year: Numeric
234−-- | , month: MonthLong
235−-- | , day: Numeric
236−-- | , hour: Numeric
237−-- | , minute: Numeric
238−-- | , second: Numeric
239−-- | }
240−-- | )
241−-- | )
242−-- | )
243−-- | ```
244−-- | You have predifined types: `WeekdayYearMonthDayHourMinuteSecond`,
245−-- | `WeekdayYearMonthDay`, `YearMonthDay`, `YearMonth`, `MonthDay`,
246−-- | `HourMinuteSecond`, `HourMinute`. But you can also provide your own by
247−-- | implementing `FormatComponent` class (or by deriving it), e.g.
248−-- | ``` purescript
249−-- | newtype EraYear = EraYear
250−-- | { era :: StringRep
251−-- | , year :: NumericRep
252−-- | }
253−-- |
254−-- | derive instance genericEraYear :: Generic EraYear _
255−-- |
256−-- | instance formatComponentEraYear :: FormatComponent EraYear where
257−-- | formatComponent = genericFormatComponent
258−-- |
259−-- | fmtEraYear :: F DateTimeFormat
260−-- | fmtEraYear = createDateTimeFormat locales opts
261−-- | where
262−-- | locale = inj (SProxy :: SProxy "locale") "en-GB"
263−-- | opts :: DateTimeFormatOptions EraYear
264−-- | opts =
265−-- | (DateTimeFormatOptions
266−-- | { localeMatcher: Nothing
267−-- | , timeZone: (Just (TimeZone "Europe/London"))
268−-- | , hour12: Just true
269−-- | , formatMatcher: Nothing
270−-- | }
271−-- | (inj
272−-- | (SProxy :: SProxy "custom")
273−-- | (EraYear
274−-- | { era: Long
275−-- | , year: Numeric
276−-- | }
277−-- | )
278−-- | )
279−-- | )
280−-- | ```
281199createDateTimeFormat
282200 :: forall a
283201 .(FormatComponent a)
@@ -291,12 +209,6 @@ createDateTimeFormat ls opts =
291209 (toLocale ls)
292210 (formatDateTimeOptions opts)
293211
294−-- | Examples
295−-- | ``` purescript
296−-- | formatJSDate (either (const "") id $ runExcept fmtHourMinute) date -- "12:00"
297−-- | formatJSDate (either (const "") id $ fmtDate) date -- "Tue, January 2, 2018, 12:00:00 PM"
298−-- | formatJSDate (either (const "") id $ fmtEraYear) date -- "2018 Anno Domini"
299−-- | ```
300212foreign import formatJSDate :: DateTimeFormat -> JSDate -> String
301213
302214foreign import supportedLocalesOfImpl
@@ -305,7 +217,7 @@ foreign import supportedLocalesOfImpl
305217 (Array String -> Either String (Array String))
306218 (Array String)
307219 (Either String (Array String))
308−
220+
309221foreign import formatToPartsImpl :: DateTimeFormat -> JSDate -> Array Foreign
310222
311223formatToParts :: DateTimeFormat -> JSDate -> F (Array FormatParts)
src/Data/Intl/DateTimeFormat/Class.purs+1−3
@@ -2,7 +2,7 @@ module Data.Intl.DateTimeFormat.Class where
22
33import Data.Maybe (Maybe(..))
44import Data.Newtype (class Newtype)
5−import Prelude (class Eq, Unit)
5+import Prelude (Unit)
66
77newtype FormatComponentRecord = FormatComponentRecord
88 { era :: Maybe String
@@ -18,8 +18,6 @@ newtype FormatComponentRecord = FormatComponentRecord
1818
1919derive instance newtypeFormatComponentRecord :: Newtype FormatComponentRecord _
2020
21−derive instance eqFormatComponentRecord :: Eq FormatComponentRecord
22−
2321defaultComponentRecord :: FormatComponentRecord
2422defaultComponentRecord = FormatComponentRecord
2523 { era: Nothing
src/Data/Intl/DateTimeFormat/Types.purs+1−28
@@ -22,16 +22,13 @@ import Data.Foreign.Index ((!))
2222import Data.Intl.DateTimeFormat.Class (class FormatComponent, FormatComponentRecord(..), defaultComponentRecord)
2323import Data.Maybe (Maybe(..))
2424import Data.Newtype (class Newtype, over)
25−import Prelude (class Eq, class Show, bind, pure, show, ($), (<>), (>>=))
25+import Prelude (class Show, bind, pure, show, ($), (<>), (>>=))
2626
2727foreign import data Undefined :: Type
28−
2928foreign import undefined :: Undefined
3029
3130data StringRep = Narrow | Short | Long
3231
33−derive instance eqStringRep :: Eq StringRep
34−
3532instance showStringRep :: Show StringRep where
3633 show Narrow = "narrow"
3734 show Short = "short"
@@ -39,16 +36,12 @@ instance showStringRep :: Show StringRep where
3936
4037data NumericRep = Numeric | TwoDigit
4138
42−derive instance eqNumericRep :: Eq NumericRep
43−
4439instance showNumericRep :: Show NumericRep where
4540 show Numeric = "numeric"
4641 show TwoDigit = "2-digit"
4742
4843data MonthRep = MonthNumeric | MonthTwoDigit | MonthNarrow | MonthShort | MonthLong
4944
50−derive instance eqMonthRep :: Eq MonthRep
51−
5245instance showMonthRep :: Show MonthRep where
5346 show MonthNumeric = "numeric"
5447 show MonthTwoDigit = "2-digit"
@@ -58,8 +51,6 @@ instance showMonthRep :: Show MonthRep where
5851
5952data TimeZoneNameRep = TimeZoneNameShort | TimeZoneNameLong
6053
61−derive instance eqTimeZoneNameRep :: Eq TimeZoneNameRep
62−
6354instance showTimeZoneRep :: Show TimeZoneNameRep where
6455 show TimeZoneNameShort = "short"
6556 show TimeZoneNameLong = "long"
@@ -75,8 +66,6 @@ data FormatParts
7566 | DayPeriod String
7667 | Literal String
7768
78−derive instance eqFormatParts :: Eq FormatParts
79−
8069readFormatParts :: Foreign -> F FormatParts
8170readFormatParts val = do
8271 type_ <- val ! "type" >>= readString
@@ -111,8 +100,6 @@ newtype ResolvedOptions = ResolvedOptions
111100
112101derive instance newtypeResolvedOptions :: Newtype ResolvedOptions _
113102
114−derive instance eqResolvedOptions :: Eq ResolvedOptions
115−
116103newtype WeekdayYearMonthDayHourMinuteSecond = WeekdayYearMonthDayHourMinuteSecond
117104 { weekday :: StringRep
118105 , year :: NumericRep
@@ -125,8 +112,6 @@ newtype WeekdayYearMonthDayHourMinuteSecond = WeekdayYearMonthDayHourMinuteSecon
125112
126113derive instance newtypeWeekdayYearMonthDayHourMinuteSecond :: Newtype WeekdayYearMonthDayHourMinuteSecond _
127114
128−derive instance eqWeekdayYearMonthDayHourMinuteSecond :: Eq WeekdayYearMonthDayHourMinuteSecond
129−
130115instance formatComponentWeekdayYearMonthDayHourMinuteSecond :: FormatComponent WeekdayYearMonthDayHourMinuteSecond where
131116 formatComponent (WeekdayYearMonthDayHourMinuteSecond { weekday, year, month, day, hour, minute, second }) = over FormatComponentRecord
132117 (\r -> r { weekday = Just (show weekday)
@@ -148,8 +133,6 @@ newtype WeekdayYearMonthDay = WeekdayYearMonthDay
148133
149134derive instance newtypeWeekdayYearMonthDay :: Newtype WeekdayYearMonthDay _
150135
151−derive instance eqWeekdayYearMonthDay :: Eq WeekdayYearMonthDay
152−
153136instance formatComponentWeekdayYearMonthDay :: FormatComponent WeekdayYearMonthDay where
154137 formatComponent (WeekdayYearMonthDay { weekday, year, month, day }) = over FormatComponentRecord
155138 (\r -> r { weekday = Just (show weekday)
@@ -168,8 +151,6 @@ newtype YearMonthDay = YearMonthDay
168151
169152derive instance newtypeYearMonthDay :: Newtype YearMonthDay _
170153
171−derive instance eqYearMonthDay :: Eq YearMonthDay
172−
173154instance formatComponentYearMonthDay :: FormatComponent YearMonthDay where
174155 formatComponent (YearMonthDay { year, month, day }) = over FormatComponentRecord
175156 (\r -> r { year = Just (show year)
@@ -186,8 +167,6 @@ newtype YearMonth = YearMonth
186167
187168derive instance newtypeYearMonth :: Newtype YearMonth _
188169
189−derive instance eqYearMonth :: Eq YearMonth
190−
191170instance formatComponentYearMonth :: FormatComponent YearMonth where
192171 formatComponent (YearMonth { year, month }) = over FormatComponentRecord
193172 (\r -> r { year = Just (show year)
@@ -202,8 +181,6 @@ newtype MonthDay = MonthDay
202181
203182derive instance newtypeMonthDay :: Newtype MonthDay _
204183
205−derive instance eqMonthDay :: Eq MonthDay
206−
207184instance formatComponentMonthDay :: FormatComponent MonthDay where
208185 formatComponent (MonthDay { month, day }) = over FormatComponentRecord
209186 (\r -> r { month = Just (show month)
@@ -219,8 +196,6 @@ newtype HourMinuteSecond = HourMinuteSecond
219196
220197derive instance newtypeHourMinuteSecond :: Newtype HourMinuteSecond _
221198
222−derive instance eqHourMinuteSecond :: Eq HourMinuteSecond
223−
224199instance formatComponentHourMinuteSecond :: FormatComponent HourMinuteSecond where
225200 formatComponent (HourMinuteSecond { hour, minute, second }) = over FormatComponentRecord
226201 (\r -> r { hour = Just (show hour)
@@ -236,8 +211,6 @@ newtype HourMinute = HourMinute
236211
237212derive instance newtypeHourMinute :: Newtype HourMinute _
238213
239−derive instance eqHourMinute :: Eq HourMinute
240−
241214instance formatComponentHourMinute :: FormatComponent HourMinute where
242215 formatComponent (HourMinute { hour, minute }) = over FormatComponentRecord
243216 (\r -> r { hour = Just (show hour)