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

Function dateGetter

packages/common/src/i18n/format_date.ts:319–343  ·  view source on GitHub ↗

* Returns a date formatter that transforms a date into its locale digit representation

(
  name: DateType,
  size: number,
  offset: number = 0,
  trim = false,
  negWrap = false,
)

Source from the content-addressed store, hash-verified

317 * Returns a date formatter that transforms a date into its locale digit representation
318 */
319function dateGetter(
320 name: DateType,
321 size: number,
322 offset: number = 0,
323 trim = false,
324 negWrap = false,
325): DateFormatter {
326 return function (date: Date, locale: string): string {
327 let part = getDatePart(name, date);
328 if (offset > 0 || part > -offset) {
329 part += offset;
330 }
331
332 if (name === DateType.Hours) {
333 if (part === 0 && offset === -12) {
334 part = 12;
335 }
336 } else if (name === DateType.FractionalSeconds) {
337 return formatFractionalSeconds(part, size);
338 }
339
340 const localeMinus = getLocaleNumberSymbol(locale, NumberSymbol.MinusSign);
341 return padNumber(part, size, localeMinus, trim, negWrap);
342 };
343}
344
345function getDatePart(part: DateType, date: Date): number {
346 switch (part) {

Callers 1

getDateFormatterFunction · 0.85

Calls 4

getLocaleNumberSymbolFunction · 0.90
getDatePartFunction · 0.85
formatFractionalSecondsFunction · 0.85
padNumberFunction · 0.85

Tested by

no test coverage detected