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

Function timeZoneGetter

packages/common/src/i18n/format_date.ts:465–505  ·  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

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

Callers 1

getDateFormatterFunction · 0.85

Calls 2

getLocaleNumberSymbolFunction · 0.90
padNumberFunction · 0.85

Tested by

no test coverage detected