|
1 |
| -import { |
2 |
| - getDateTimeFormatOptions, |
3 |
| - parseDateTokens |
4 |
| -} from '@messageformat/date-skeleton'; |
5 | 1 | import {
|
6 | 2 | getNumberFormatOptions,
|
7 | 3 | parseNumberPattern,
|
@@ -54,27 +50,6 @@ function findSelectArgs(tokens: AST.Token[]): SelectArg[] {
|
54 | 50 | return args;
|
55 | 51 | }
|
56 | 52 |
|
57 |
| -function parseDateTimeArgStyle(argStyle: string): MF.Options { |
58 |
| - const options: MF.Options = new Map(); |
59 |
| - const onError = () => |
60 |
| - options.set('mf1:argStyle', { type: 'literal', value: argStyle }); |
61 |
| - const tokens = parseDateTokens(argStyle.substring(2)); |
62 |
| - const dtfOpt = getDateTimeFormatOptions(tokens, onError); |
63 |
| - loop: for (let [key, value] of Object.entries(dtfOpt)) { |
64 |
| - switch (key) { |
65 |
| - case 'dayPeriod': |
66 |
| - onError(); |
67 |
| - continue loop; |
68 |
| - case 'hourCycle': |
69 |
| - key = 'hour12'; |
70 |
| - value = String(value === 'h11' || value === 'h12'); |
71 |
| - break; |
72 |
| - } |
73 |
| - options.set(key, { type: 'literal', value }); |
74 |
| - } |
75 |
| - return options; |
76 |
| -} |
77 |
| - |
78 | 53 | function parseNumberArgStyle(argStyle: string): MF.FunctionRef {
|
79 | 54 | let name = 'number';
|
80 | 55 | const options: MF.Options = new Map();
|
@@ -155,36 +130,27 @@ function tokenToFunctionRef(token: AST.FunctionArg): {
|
155 | 130 |
|
156 | 131 | switch (token.key) {
|
157 | 132 | case 'date': {
|
158 |
| - let options: MF.Options; |
159 |
| - if (argStyle.startsWith('::')) { |
160 |
| - options = parseDateTimeArgStyle(argStyle); |
161 |
| - } else { |
162 |
| - const month: MF.Literal = { type: 'literal', value: 'short' }; |
163 |
| - options = new Map([ |
164 |
| - ['year', { type: 'literal', value: 'numeric' }], |
165 |
| - ['month', month], |
166 |
| - ['day', { type: 'literal', value: 'numeric' }] |
167 |
| - ]); |
168 |
| - switch (argStyle) { |
169 |
| - case 'full': |
170 |
| - month.value = 'long'; |
171 |
| - options.set('weekday', { type: 'literal', value: 'long' }); |
172 |
| - break; |
173 |
| - case 'long': |
174 |
| - month.value = 'long'; |
175 |
| - break; |
176 |
| - case 'short': |
177 |
| - month.value = 'numeric'; |
178 |
| - break; |
179 |
| - case '': |
180 |
| - case 'medium': |
181 |
| - break; |
182 |
| - default: |
183 |
| - options.set('mf1:argStyle', { type: 'literal', value: argStyle }); |
184 |
| - } |
| 133 | + const options: MF.Options = new Map(); |
| 134 | + switch (argStyle) { |
| 135 | + case '': |
| 136 | + break; |
| 137 | + case 'full': |
| 138 | + options.set('fields', { |
| 139 | + type: 'literal', |
| 140 | + value: 'year-month-day-weekday' |
| 141 | + }); |
| 142 | + options.set('length', { type: 'literal', value: 'long' }); |
| 143 | + break; |
| 144 | + case 'long': |
| 145 | + case 'medium': |
| 146 | + case 'short': |
| 147 | + options.set('length', { type: 'literal', value: argStyle }); |
| 148 | + break; |
| 149 | + default: |
| 150 | + options.set('mf1:argStyle', { type: 'literal', value: argStyle }); |
185 | 151 | }
|
186 | 152 | return {
|
187 |
| - functionRef: { type: 'function', name: 'mf1:datetime', options }, |
| 153 | + functionRef: { type: 'function', name: 'mf1:date', options }, |
188 | 154 | attributes
|
189 | 155 | };
|
190 | 156 | }
|
@@ -223,32 +189,28 @@ function tokenToFunctionRef(token: AST.FunctionArg): {
|
223 | 189 | }
|
224 | 190 |
|
225 | 191 | case 'time': {
|
226 |
| - let options: MF.Options; |
227 |
| - if (argStyle.startsWith('::')) { |
228 |
| - options = parseDateTimeArgStyle(argStyle); |
229 |
| - } else { |
230 |
| - options = new Map([ |
231 |
| - ['hour', { type: 'literal', value: 'numeric' }], |
232 |
| - ['minute', { type: 'literal', value: 'numeric' }] |
233 |
| - ]); |
234 |
| - switch (argStyle) { |
235 |
| - case 'full': |
236 |
| - case 'long': |
237 |
| - options.set('second', { type: 'literal', value: 'numeric' }); |
238 |
| - options.set('timeZoneName', { type: 'literal', value: 'short' }); |
239 |
| - break; |
240 |
| - case 'short': |
241 |
| - break; |
242 |
| - case '': |
243 |
| - case 'medium': |
244 |
| - options.set('second', { type: 'literal', value: 'numeric' }); |
245 |
| - break; |
246 |
| - default: |
247 |
| - options.set('mf1:argStyle', { type: 'literal', value: argStyle }); |
248 |
| - } |
| 192 | + const options: MF.Options = new Map(); |
| 193 | + switch (argStyle) { |
| 194 | + case 'full': |
| 195 | + options.set('precision', { type: 'literal', value: 'second' }); |
| 196 | + options.set('timeZoneName', { type: 'literal', value: 'long' }); |
| 197 | + break; |
| 198 | + case 'long': |
| 199 | + options.set('precision', { type: 'literal', value: 'second' }); |
| 200 | + options.set('timeZoneName', { type: 'literal', value: 'short' }); |
| 201 | + break; |
| 202 | + case '': |
| 203 | + case 'medium': |
| 204 | + options.set('precision', { type: 'literal', value: 'second' }); |
| 205 | + break; |
| 206 | + case 'short': |
| 207 | + options.set('precision', { type: 'literal', value: 'minute' }); |
| 208 | + break; |
| 209 | + default: |
| 210 | + options.set('mf1:argStyle', { type: 'literal', value: argStyle }); |
249 | 211 | }
|
250 | 212 | return {
|
251 |
| - functionRef: { type: 'function', name: 'mf1:datetime', options }, |
| 213 | + functionRef: { type: 'function', name: 'mf1:time', options }, |
252 | 214 | attributes
|
253 | 215 | };
|
254 | 216 | }
|
|
0 commit comments