MCPcopy Index your code
hub / github.com/angular/angular / timeZoneGetter

Function timeZoneGetter

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

* Returns a date formatter that transforms a date and an offset into a timezone with ISO8601 or * GMT format depending on the width (eg: short = +0430, short:GMT = GMT+4, long = GMT+04:30, * extended = +04:30)

(width: ZoneWidth)

Source from the content-addressed store, hash-verified

462 * extended = +04:30)
463 */
464function timeZoneGetter(width: ZoneWidth): DateFormatter {
465 return function (date: Date, locale: string, offset: number) {
466 const zone = -1 * offset;
467 const minusSign = getLocaleNumberSymbol(locale, NumberSymbol.MinusSign);
468 const hours = zone > 0 ? Math.floor(zone / 60) : Math.ceil(zone / 60);
469 switch (width) {
470 case ZoneWidth.Short:
471 return (
472 (zone >= 0 ? '+' : '') +
473 padNumber(hours, 2, minusSign) +
474 padNumber(Math.abs(zone % 60), 2, minusSign)
475 );
476 case ZoneWidth.ShortGMT:
477 return 'GMT' + (zone >= 0 ? '+' : '') + padNumber(hours, 1, minusSign);
478 case ZoneWidth.Long:
479 return (
480 'GMT' +
481 (zone >= 0 ? '+' : '') +
482 padNumber(hours, 2, minusSign) +
483 ':' +
484 padNumber(Math.abs(zone % 60), 2, minusSign)
485 );
486 case ZoneWidth.Extended:
487 if (offset === 0) {
488 return 'Z';
489 } else {
490 return (
491 (zone >= 0 ? '+' : '') +
492 padNumber(hours, 2, minusSign) +
493 ':' +
494 padNumber(Math.abs(zone % 60), 2, minusSign)
495 );
496 }
497 default:
498 throw new RuntimeError(
499 RuntimeErrorCode.UNKNOWN_ZONE_WIDTH,
500 ngDevMode && `Unknown zone width "${width}"`,
501 );
502 }
503 };
504}
505
506const JANUARY = 0;
507const THURSDAY = 4;

Callers 1

getDateFormatterFunction · 0.85

Calls 2

getLocaleNumberSymbolFunction · 0.90
padNumberFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…