git.iko.soy/purescript-intl
on master help sign in
Reshuffle modules
986e20eMarcin Szamotulski
src/Data/Intl/DateTimeFormat.purs−91
@@ -3,15 +3,6 @@ module Data.Intl.DateTimeFormat
3 , LocaleMatcher(..)
3 , LocaleMatcher(..)
4 , TimeZone(..)
4 , TimeZone(..)
5 , FormatMatcher(..)
5 , FormatMatcher(..)
6− , WeekdayYearMonthDayHourMinuteSecond(..)
7− , WeekdayYearMonthDay(..)
8− , YearMonthDay(..)
9− , YearMonth(..)
10− , MonthDay(..)
11− , HourMinuteSecond(..)
12− , HourMinute(..)
13− , Undefined
14− , undefined
15 , DateTimeFormatOptions(..)
6 , DateTimeFormatOptions(..)
16 , DateTimeFormatOptions'
7 , DateTimeFormatOptions'
17 , DateTimeComponents(..)
8 , DateTimeComponents(..)
@@ -45,9 +36,6 @@ import Unsafe.Coerce (unsafeCoerce)
45
36
46foreign import data LocalesOption' :: Type
37foreign import data LocalesOption' :: Type
47
38
48−foreign import data Undefined :: Type
49−foreign import undefined :: Undefined
50−
51foreign import dateTimeFormatImpl :: LocalesOption' -> DateTimeFormatOptions_ -> DateTimeFormat
39foreign import dateTimeFormatImpl :: LocalesOption' -> DateTimeFormatOptions_ -> DateTimeFormat
52
40
53newtype DateTimeFormatOptions_ = DateTimeFormatOptions_
41newtype DateTimeFormatOptions_ = DateTimeFormatOptions_
@@ -99,85 +87,6 @@ instance showFormatMatcher :: Show FormatMatcher where
99 show FMBasic = "basic"
87 show FMBasic = "basic"
100 show FMBestFit = "best fit"
88 show FMBestFit = "best fit"
101
89
102−newtype WeekdayYearMonthDayHourMinuteSecond = WeekdayYearMonthDayHourMinuteSecond
103− { weekday :: StringRep
104− , year :: NumericRep
105− , month :: MonthRep
106− , day :: NumericRep
107− , hour :: NumericRep
108− , minute :: NumericRep
109− , second :: NumericRep
110− }
111−
112−derive instance genericWeekdayYearMonthDayHourMinuteSecond :: Generic WeekdayYearMonthDayHourMinuteSecond _
113−
114−instance formatComponentWeekdayYearMonthDayHourMinuteSecond :: FormatComponent WeekdayYearMonthDayHourMinuteSecond where
115− formatComponent = genericFormatComponent
116−
117−newtype WeekdayYearMonthDay = WeekdayYearMonthDay
118− { weekday :: StringRep
119− , year :: NumericRep
120− , month :: MonthRep
121− , day :: NumericRep
122− }
123−
124−derive instance genericWeekdayYearMonthDay :: Generic WeekdayYearMonthDay _
125−
126−instance formatComponentWeekdayYearMonthDay :: FormatComponent WeekdayYearMonthDay where
127− formatComponent = genericFormatComponent
128−
129−newtype YearMonthDay = YearMonthDay
130− { year :: NumericRep
131− , month :: MonthRep
132− , day :: NumericRep
133− }
134−
135−derive instance genericYearMonthDay :: Generic YearMonthDay _
136−
137−instance formatComponentYearMonthDay :: FormatComponent YearMonthDay where
138− formatComponent = genericFormatComponent
139−
140−newtype YearMonth = YearMonth
141− { year :: NumericRep
142− , month :: MonthRep
143− }
144−
145−derive instance genericYearMonth :: Generic YearMonth _
146−
147−instance formatComponentYearMonth :: FormatComponent YearMonth where
148− formatComponent = genericFormatComponent
149−
150−newtype MonthDay = MonthDay
151− { month :: MonthRep
152− , day :: NumericRep
153− }
154−
155−derive instance genericMonthDay :: Generic MonthDay _
156−
157−instance formatComponentMonthDay :: FormatComponent MonthDay where
158− formatComponent = genericFormatComponent
159−
160−newtype HourMinuteSecond = HourMinuteSecond
161− { hour :: NumericRep
162− , minute :: NumericRep
163− , second :: NumericRep
164− }
165−
166−derive instance genericHourMinuteSecond :: Generic HourMinuteSecond _
167−
168−instance formatComponentHourMinuteSecond :: FormatComponent HourMinuteSecond where
169− formatComponent = genericFormatComponent
170−
171−newtype HourMinute = HourMinute
172− { hour :: NumericRep
173− , minute :: NumericRep
174− }
175−
176−derive instance genericHourMinute :: Generic HourMinute _
177−
178−instance formatComponentHourMinute :: FormatComponent HourMinute where
179− formatComponent = genericFormatComponent
180−
181type DateTimeComponents a =
90type DateTimeComponents a =
182 Variant
91 Variant
183 ( weekdayYearMonthDayHourMinuteSecond :: WeekdayYearMonthDayHourMinuteSecond
92 ( weekdayYearMonthDayHourMinuteSecond :: WeekdayYearMonthDayHourMinuteSecond
src/Data/Intl/DateTimeFormat/Class.pursnew file+36
@@ -0,0 +1,36 @@
1+module Data.Intl.DateTimeFormat.Class where
2+
3+import Data.Maybe (Maybe(..))
4+import Prelude (Unit)
5+
6+type FormatComponentRecord =
7+ { era :: Maybe String
8+ , weekday :: Maybe String
9+ , year :: Maybe String
10+ , month :: Maybe String
11+ , day :: Maybe String
12+ , hour :: Maybe String
13+ , minute :: Maybe String
14+ , second :: Maybe String
15+ , timeZoneName :: Maybe String
16+ }
17+
18+defaultComponentRecord :: FormatComponentRecord
19+defaultComponentRecord =
20+ { era: Nothing
21+ , weekday: Nothing
22+ , year: Nothing
23+ , month: Nothing
24+ , day: Nothing
25+ , hour: Nothing
26+ , minute: Nothing
27+ , second: Nothing
28+ , timeZoneName: Nothing
29+ }
30+
31+
32+class FormatComponent a where
33+ formatComponent :: a -> FormatComponentRecord
34+
35+instance unitFormatComponent :: FormatComponent Unit where
36+ formatComponent _ = defaultComponentRecord
src/Data/Intl/DateTimeFormat/Generic.purs+3−37
@@ -1,51 +1,17 @@
1module Data.Intl.DateTimeFormat.Generic
1module Data.Intl.DateTimeFormat.Generic
2− ( class FormatComponent
3− , formatComponent
4− , class GenericFormatComponent
2+ ( class GenericFormatComponent
5 , genericFormatComponent'
3 , genericFormatComponent'
6 , genericFormatComponent
4 , genericFormatComponent
7 , class GenericFormatComponentFields
5 , class GenericFormatComponentFields
8 , genericFormatComponentFields
6 , genericFormatComponentFields
9− , defaultComponentRecord
10− , FormatComponentRecord
11 ) where
7 ) where
12
8
13import Data.Generic.Rep (class Generic, Constructor(Constructor), Field(..), NoConstructors, Product(..), Rec(..), from)
9import Data.Generic.Rep (class Generic, Constructor(Constructor), Field(..), NoConstructors, Product(..), Rec(..), from)
10+import Data.Intl.DateTimeFormat.Class (FormatComponentRecord)
14import Data.Intl.DateTimeFormat.Types (MonthRep, NumericRep, TimeZoneNameRep, StringRep)
11import Data.Intl.DateTimeFormat.Types (MonthRep, NumericRep, TimeZoneNameRep, StringRep)
15import Data.Maybe (Maybe(..))
12import Data.Maybe (Maybe(..))
16import Data.StrMap (StrMap, lookup, singleton, union)
13import Data.StrMap (StrMap, lookup, singleton, union)
17−import Prelude (Unit, show)
14+import Prelude (show)
18−
19−type FormatComponentRecord =
20− { era :: Maybe String
21− , weekday :: Maybe String
22− , year :: Maybe String
23− , month :: Maybe String
24− , day :: Maybe String
25− , hour :: Maybe String
26− , minute :: Maybe String
27− , second :: Maybe String
28− , timeZoneName :: Maybe String
29− }
30−
31−defaultComponentRecord :: FormatComponentRecord
32−defaultComponentRecord =
33− { era: Nothing
34− , weekday: Nothing
35− , year: Nothing
36− , month: Nothing
37− , day: Nothing
38− , hour: Nothing
39− , minute: Nothing
40− , second: Nothing
41− , timeZoneName: Nothing
42− }
43−
44−class FormatComponent a where
45− formatComponent :: a -> FormatComponentRecord
46−
47−instance unitFormatComponent :: FormatComponent Unit where
48− formatComponent _ = defaultComponentRecord
49
15
50class GenericFormatComponent a where
16class GenericFormatComponent a where
51 genericFormatComponent' :: a -> FormatComponentRecord
17 genericFormatComponent' :: a -> FormatComponentRecord
src/Data/Intl/DateTimeFormat/Types.jsnew file+3
@@ -0,0 +1,3 @@
1+"use strict";
2+
3+exports["undefined"] = undefined;
src/Data/Intl/DateTimeFormat/Types.purs+94
@@ -6,14 +6,29 @@ module Data.Intl.DateTimeFormat.Types
6 , FormatParts(..)
6 , FormatParts(..)
7 , readFormatParts
7 , readFormatParts
8 , ResolvedOptions(..)
8 , ResolvedOptions(..)
9+ , WeekdayYearMonthDayHourMinuteSecond(..)
10+ , WeekdayYearMonthDay(..)
11+ , YearMonthDay(..)
12+ , YearMonth(..)
13+ , MonthDay(..)
14+ , HourMinuteSecond(..)
15+ , HourMinute(..)
16+ , Undefined
17+ , undefined
9 ) where
18 ) where
10
19
11import Data.Foreign (F, Foreign, ForeignError(..), fail, readString)
20import Data.Foreign (F, Foreign, ForeignError(..), fail, readString)
12import Data.Foreign.Index ((!))
21import Data.Foreign.Index ((!))
22+import Data.Generic (class Generic)
23+import Data.Intl.DateTimeFormat.Class (class FormatComponent)
24+import Data.Intl.DateTimeFormat.Generic (genericFormatComponent)
13import Data.Maybe (Maybe)
25import Data.Maybe (Maybe)
14import Data.Newtype (class Newtype)
26import Data.Newtype (class Newtype)
15import Prelude (class Show, bind, pure, ($), (<>), (>>=))
27import Prelude (class Show, bind, pure, ($), (<>), (>>=))
16
28
29+foreign import data Undefined :: Type
30+foreign import undefined :: Undefined
31+
17data StringRep = Narrow | Short | Long
32data StringRep = Narrow | Short | Long
18
33
19instance showStringRep :: Show StringRep where
34instance showStringRep :: Show StringRep where
@@ -86,3 +101,82 @@ newtype ResolvedOptions = ResolvedOptions
86 }
101 }
87
102
88derive instance newtypeResolvedOptions :: Newtype ResolvedOptions _
103derive instance newtypeResolvedOptions :: Newtype ResolvedOptions _
104+
105+newtype WeekdayYearMonthDayHourMinuteSecond = WeekdayYearMonthDayHourMinuteSecond
106+ { weekday :: StringRep
107+ , year :: NumericRep
108+ , month :: MonthRep
109+ , day :: NumericRep
110+ , hour :: NumericRep
111+ , minute :: NumericRep
112+ , second :: NumericRep
113+ }
114+
115+derive instance genericWeekdayYearMonthDayHourMinuteSecond :: Generic WeekdayYearMonthDayHourMinuteSecond _
116+
117+instance formatComponentWeekdayYearMonthDayHourMinuteSecond :: FormatComponent WeekdayYearMonthDayHourMinuteSecond where
118+ formatComponent = genericFormatComponent
119+
120+newtype WeekdayYearMonthDay = WeekdayYearMonthDay
121+ { weekday :: StringRep
122+ , year :: NumericRep
123+ , month :: MonthRep
124+ , day :: NumericRep
125+ }
126+
127+derive instance genericWeekdayYearMonthDay :: Generic WeekdayYearMonthDay _
128+
129+instance formatComponentWeekdayYearMonthDay :: FormatComponent WeekdayYearMonthDay where
130+ formatComponent = genericFormatComponent
131+
132+newtype YearMonthDay = YearMonthDay
133+ { year :: NumericRep
134+ , month :: MonthRep
135+ , day :: NumericRep
136+ }
137+
138+derive instance genericYearMonthDay :: Generic YearMonthDay _
139+
140+instance formatComponentYearMonthDay :: FormatComponent YearMonthDay where
141+ formatComponent = genericFormatComponent
142+
143+newtype YearMonth = YearMonth
144+ { year :: NumericRep
145+ , month :: MonthRep
146+ }
147+
148+derive instance genericYearMonth :: Generic YearMonth _
149+
150+instance formatComponentYearMonth :: FormatComponent YearMonth where
151+ formatComponent = genericFormatComponent
152+
153+newtype MonthDay = MonthDay
154+ { month :: MonthRep
155+ , day :: NumericRep
156+ }
157+
158+derive instance genericMonthDay :: Generic MonthDay _
159+
160+instance formatComponentMonthDay :: FormatComponent MonthDay where
161+ formatComponent = genericFormatComponent
162+
163+newtype HourMinuteSecond = HourMinuteSecond
164+ { hour :: NumericRep
165+ , minute :: NumericRep
166+ , second :: NumericRep
167+ }
168+
169+derive instance genericHourMinuteSecond :: Generic HourMinuteSecond _
170+
171+instance formatComponentHourMinuteSecond :: FormatComponent HourMinuteSecond where
172+ formatComponent = genericFormatComponent
173+
174+newtype HourMinute = HourMinute
175+ { hour :: NumericRep
176+ , minute :: NumericRep
177+ }
178+
179+derive instance genericHourMinute :: Generic HourMinute _
180+
181+instance formatComponentHourMinute :: FormatComponent HourMinute where
182+ formatComponent = genericFormatComponent