MCPcopy Create free account
hub / github.com/angular/angular / getNamedFormat

Function getNamedFormat

packages/common/src/i18n/format_date.ts:203–274  ·  view source on GitHub ↗
(locale: string, format: string)

Source from the content-addressed store, hash-verified

201}
202
203function getNamedFormat(locale: string, format: string): string {
204 const localeId = getLocaleId(locale);
205 NAMED_FORMATS[localeId] ??= Object.create(null);
206
207 if (NAMED_FORMATS[localeId][format]) {
208 return NAMED_FORMATS[localeId][format];
209 }
210
211 let formatValue = '';
212 switch (format) {
213 case 'shortDate':
214 formatValue = getLocaleDateFormat(locale, FormatWidth.Short);
215 break;
216 case 'mediumDate':
217 formatValue = getLocaleDateFormat(locale, FormatWidth.Medium);
218 break;
219 case 'longDate':
220 formatValue = getLocaleDateFormat(locale, FormatWidth.Long);
221 break;
222 case 'fullDate':
223 formatValue = getLocaleDateFormat(locale, FormatWidth.Full);
224 break;
225 case 'shortTime':
226 formatValue = getLocaleTimeFormat(locale, FormatWidth.Short);
227 break;
228 case 'mediumTime':
229 formatValue = getLocaleTimeFormat(locale, FormatWidth.Medium);
230 break;
231 case 'longTime':
232 formatValue = getLocaleTimeFormat(locale, FormatWidth.Long);
233 break;
234 case 'fullTime':
235 formatValue = getLocaleTimeFormat(locale, FormatWidth.Full);
236 break;
237 case 'short':
238 const shortTime = getNamedFormat(locale, 'shortTime');
239 const shortDate = getNamedFormat(locale, 'shortDate');
240 formatValue = formatDateTime(getLocaleDateTimeFormat(locale, FormatWidth.Short), [
241 shortTime,
242 shortDate,
243 ]);
244 break;
245 case 'medium':
246 const mediumTime = getNamedFormat(locale, 'mediumTime');
247 const mediumDate = getNamedFormat(locale, 'mediumDate');
248 formatValue = formatDateTime(getLocaleDateTimeFormat(locale, FormatWidth.Medium), [
249 mediumTime,
250 mediumDate,
251 ]);
252 break;
253 case 'long':
254 const longTime = getNamedFormat(locale, 'longTime');
255 const longDate = getNamedFormat(locale, 'longDate');
256 formatValue = formatDateTime(getLocaleDateTimeFormat(locale, FormatWidth.Long), [
257 longTime,
258 longDate,
259 ]);
260 break;

Callers 1

formatDateFunction · 0.85

Calls 6

getLocaleIdFunction · 0.90
getLocaleDateFormatFunction · 0.90
getLocaleTimeFormatFunction · 0.90
getLocaleDateTimeFormatFunction · 0.90
formatDateTimeFunction · 0.85
createMethod · 0.65

Tested by

no test coverage detected