1module Data.Intl.DateTimeFormat.Generic
2 ( class FormatComponent
4 , class GenericFormatComponent
5 , genericFormatComponent'
6 , genericFormatComponent
7 , class GenericFormatComponentFields
8 , genericFormatComponentFields
9 , defaultComponentRecord
10 , FormatComponentRecord
13import Data.Generic.Rep (class Generic, Constructor(Constructor), Field(..), NoConstructors, Product(..), Rec(..), from)
14import Data.Intl.DateTimeFormat.Types (MonthRep, NumericRep, TimeZoneNameRep, StringRep)
15import Data.Maybe (Maybe(..))
16import Data.StrMap (StrMap, lookup, singleton, union)
17import Prelude (Unit, show)
19type FormatComponentRecord =
21 , weekday :: Maybe String
22 , year :: Maybe String
23 , month :: Maybe String
25 , hour :: Maybe String
26 , minute :: Maybe String
27 , second :: Maybe String
28 , timeZoneName :: Maybe String
31defaultComponentRecord :: FormatComponentRecord
32defaultComponentRecord =
41 , timeZoneName: Nothing
44class FormatComponent a where
45 formatComponent :: a -> FormatComponentRecord
47instance unitFormatComponent :: FormatComponent Unit where
48 formatComponent _ = defaultComponentRecord
50class GenericFormatComponent a where
51 genericFormatComponent' :: a -> FormatComponentRecord
53class GenericFormatComponentFields a where
54 genericFormatComponentFields :: a -> StrMap String
56instance genericFormatComponentNoConsturctors :: GenericFormatComponent NoConstructors where
57 genericFormatComponent' a =
66 , timeZoneName: Nothing
69instance genericFormatComponentConstructor :: (GenericFormatComponent a) => GenericFormatComponent (Constructor name a) where
70 genericFormatComponent' (Constructor a) = genericFormatComponent' a
72instance genericFormatComponentFieldsEra
73 :: GenericFormatComponentFields (Field "era" StringRep) where
74 genericFormatComponentFields (Field a) = singleton "era" (show a)
76instance genericFormatComponentFieldsWeekday
77 :: GenericFormatComponentFields (Field "weekday" StringRep) where
78 genericFormatComponentFields (Field a) = singleton "weekday" (show a)
80instance genericFormatComponentFieldsYear
81 :: GenericFormatComponentFields (Field "year" NumericRep) where
82 genericFormatComponentFields (Field a) = singleton "year" (show a)
84instance genericFormatComponentFieldsMonth
85 :: GenericFormatComponentFields (Field "month" MonthRep) where
86 genericFormatComponentFields (Field a) = singleton "month" (show a)
88instance genericFormatComponentFieldsDay
89 :: GenericFormatComponentFields (Field "day" NumericRep) where
90 genericFormatComponentFields (Field a) = singleton "day" (show a)
92instance genericFormatComponentFieldsHour
93 :: GenericFormatComponentFields (Field "hour" NumericRep) where
94 genericFormatComponentFields (Field a) = singleton "hour" (show a)
96instance genericFormatComponentFieldsMinute
97 :: GenericFormatComponentFields (Field "minute" NumericRep) where
98 genericFormatComponentFields (Field a) = singleton "minute" (show a)
100instance genericFormatComponentFieldsSecond
101 :: GenericFormatComponentFields (Field "second" NumericRep) where
102 genericFormatComponentFields (Field a) = singleton "second" (show a)
104instance genericFormatComponentFieldsTimeZoneName
105 :: GenericFormatComponentFields (Field "timeZoneName" TimeZoneNameRep) where
106 genericFormatComponentFields (Field a) = singleton "timeZoneName" (show a)
108instance genericFormatComponentFieldsProduct
109 :: (GenericFormatComponentFields a, GenericFormatComponentFields b)
110 => GenericFormatComponentFields (Product a b) where
111 genericFormatComponentFields (Product a b) =
112 union (genericFormatComponentFields a) (genericFormatComponentFields b)
114instance genericFormatComponentRec
115 :: (GenericFormatComponentFields a)
116 => GenericFormatComponent (Rec a) where
117 genericFormatComponent' (Rec a) =
118 { era: "era" `lookup` u
119 , weekday: "weekday" `lookup` u
120 , year: "year" `lookup` u
121 , month: "month" `lookup` u
122 , day: "day" `lookup` u
123 , hour: "hour" `lookup` u
124 , minute: "minute" `lookup` u
125 , second: "second" `lookup` u
126 , timeZoneName: "timeZoneName" `lookup` u
129 u = genericFormatComponentFields a
131genericFormatComponent :: forall a rep. Generic a rep => GenericFormatComponent rep => a -> FormatComponentRecord
132genericFormatComponent a = genericFormatComponent' (from a)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list