@pega/cosmos-react-core 9.23.1 → 9.23.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"CurrencyDisplay.d.ts","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyDisplay.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,GAAG,EAAE,MAAM,OAAO,CAAC;AAElD,OAAO,KAAK,EAAE,SAAS,EAAE,+BAA+B,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAO9F,MAAM,WAAW,oBAAqB,SAAQ,SAAS,EAAE,cAAc;IACrE,oBAAoB;IACpB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,+GAA+G;IAC/G,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oCAAoC;IACpC,iBAAiB,CAAC,EAAE;QAClB,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;QACtC;;;WAGG;QACH,QAAQ,CAAC,EAAE,YAAY,GAAG,aAAa,CAAC;QACxC;;;WAGG;QACH,QAAQ,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;QAClC;;;WAGG;QACH,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB;;WAEG;QACH,eAAe,CAAC,EAAE,OAAO,CAAC;KAC3B,CAAC;IACF,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC,iBAAiB,CAAC,CAAC;CAC9B;AAED,QAAA,MAAM,eAAe,EAAE,+BAA+B,CAAC,oBAAoB,CAsD1E,CAAC;AAEF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"CurrencyDisplay.d.ts","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyDisplay.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,GAAG,EAAE,MAAM,OAAO,CAAC;AAElD,OAAO,KAAK,EAAE,SAAS,EAAE,+BAA+B,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAO9F,MAAM,WAAW,oBAAqB,SAAQ,SAAS,EAAE,cAAc;IACrE,oBAAoB;IACpB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,+GAA+G;IAC/G,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oCAAoC;IACpC,iBAAiB,CAAC,EAAE;QAClB,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;QACtC;;;WAGG;QACH,QAAQ,CAAC,EAAE,YAAY,GAAG,aAAa,CAAC;QACxC;;;WAGG;QACH,QAAQ,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;QAClC;;;WAGG;QACH,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB;;WAEG;QACH,eAAe,CAAC,EAAE,OAAO,CAAC;KAC3B,CAAC;IACF,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC,iBAAiB,CAAC,CAAC;CAC9B;AAED,QAAA,MAAM,eAAe,EAAE,+BAA+B,CAAC,oBAAoB,CAqE1E,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -1,12 +1,20 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { forwardRef } from 'react';
2
+ import { forwardRef, useMemo } from 'react';
3
3
  import { useConfiguration } from '../../hooks';
4
4
  import VisuallyHiddenText from '../VisuallyHiddenText';
5
5
  import NoValue from '../NoValue/NoValue';
6
- import { formatCurrency, isValidCurrency } from './utils';
6
+ import { formatCurrency, getCurrencyMinimumFractionDigits, isValidCurrency } from './utils';
7
7
  const CurrencyDisplay = forwardRef(function CurrencyDisplay({ value, currencyISOCode, formattingOptions: { currency = 'symbol', negative = 'minus-sign', notation = 'standard', groupSeparators = true, fractionDigits } = {}, ...restProps }, ref) {
8
8
  const { locale } = useConfiguration();
9
- const options = currencyISOCode && isValidCurrency(currencyISOCode)
9
+ const validCurrencyISOCode = useMemo(() => (currencyISOCode && isValidCurrency(currencyISOCode) ? currencyISOCode : undefined), [currencyISOCode]);
10
+ const minimumCurrencyFractionDigits = useMemo(
11
+ // Only relevant for 'standard' notation: 'compact' notation relies on Intl's own
12
+ // rounding to a small number of significant digits, which a fixed fraction digit
13
+ // count would defeat (e.g. preventing 999.99 from being abbreviated to 1K).
14
+ () => notation === 'standard'
15
+ ? getCurrencyMinimumFractionDigits(locale, validCurrencyISOCode)
16
+ : undefined, [locale, validCurrencyISOCode, notation]);
17
+ const options = validCurrencyISOCode
10
18
  ? {
11
19
  style: 'currency',
12
20
  currency: currencyISOCode,
@@ -14,8 +22,8 @@ const CurrencyDisplay = forwardRef(function CurrencyDisplay({ value, currencyISO
14
22
  useGrouping: groupSeparators,
15
23
  notation,
16
24
  currencySign: negative === 'parentheses' ? 'accounting' : 'standard',
17
- minimumFractionDigits: fractionDigits,
18
- maximumFractionDigits: fractionDigits
25
+ minimumFractionDigits: fractionDigits ?? minimumCurrencyFractionDigits,
26
+ maximumFractionDigits: fractionDigits ?? minimumCurrencyFractionDigits
19
27
  }
20
28
  : undefined;
21
29
  const srOptions = {
@@ -1 +1 @@
1
- {"version":3,"file":"CurrencyDisplay.js","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyDisplay.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAInC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,kBAAkB,MAAM,uBAAuB,CAAC;AACvD,OAAO,OAAO,MAAM,oBAAoB,CAAC;AAEzC,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAkC1D,MAAM,eAAe,GAA0D,UAAU,CACvF,SAAS,eAAe,CACtB,EACE,KAAK,EACL,eAAe,EACf,iBAAiB,EAAE,EACjB,QAAQ,GAAG,QAAQ,EACnB,QAAQ,GAAG,YAAY,EACvB,QAAQ,GAAG,UAAU,EACrB,eAAe,GAAG,IAAI,EACtB,cAAc,EACf,GAAG,EAAE,EACN,GAAG,SAAS,EAC0B,EACxC,GAAgC;IAEhC,MAAM,EAAE,MAAM,EAAE,GAAG,gBAAgB,EAAE,CAAC;IAEtC,MAAM,OAAO,GACX,eAAe,IAAI,eAAe,CAAC,eAAe,CAAC;QACjD,CAAC,CAAE;YACC,KAAK,EAAE,UAAU;YACjB,QAAQ,EAAE,eAAe;YACzB,eAAe,EAAE,QAAQ;YACzB,WAAW,EAAE,eAAe;YAC5B,QAAQ;YACR,YAAY,EAAE,QAAQ,KAAK,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU;YACpE,qBAAqB,EAAE,cAAc;YACrC,qBAAqB,EAAE,cAAc;SACT;QAChC,CAAC,CAAC,SAAS,CAAC;IAEhB,MAAM,SAAS,GAAG;QAChB,GAAG,OAAO;QACV,WAAW,EAAE,KAAK;QAClB,YAAY,EAAE,UAAU;QACxB,eAAe,EAAE,MAAM;KACW,CAAC;IAErC,OAAO,CACL,eAAM,GAAG,EAAE,GAAG,KAAM,SAAS,YAC1B,KAAK,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CACtB,8BACE,8CAAmB,cAAc,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAQ,EACrE,KAAC,kBAAkB,cAChB,cAAc,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,GACnC,IACpB,CACJ,CAAC,CAAC,CAAC,CACF,KAAC,OAAO,KAAG,CACZ,GACI,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { forwardRef } from 'react';\nimport type { PropsWithoutRef, Ref } from 'react';\n\nimport type { BaseProps, ForwardRefForwardPropsComponent, NoChildrenProp } from '../../types';\nimport { useConfiguration } from '../../hooks';\nimport VisuallyHiddenText from '../VisuallyHiddenText';\nimport NoValue from '../NoValue/NoValue';\n\nimport { formatCurrency, isValidCurrency } from './utils';\n\nexport interface CurrencyDisplayProps extends BaseProps, NoChildrenProp {\n /** Number value. */\n value?: number | bigint;\n /** Three letter currency shorthand ISO code. If not provided or invalid, component renders only the number. */\n currencyISOCode?: string;\n /** Options to define formatting. */\n formattingOptions?: {\n currency?: 'symbol' | 'code' | 'name';\n /**\n * Determines negative value notation: using minus sign or parentheses.\n * @default 'minus-sign'\n */\n negative?: 'minus-sign' | 'parentheses';\n /**\n * Value display notation.\n * @default 'standard'\n */\n notation?: 'standard' | 'compact';\n /**\n * Fixed number of fraction digits. Maximum is 20, default is currency dependant.\n * @default variable\n */\n fractionDigits?: number;\n /** Determines whether group separators should be shown.\n * @default true\n */\n groupSeparators?: boolean;\n };\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLAnchorElement>;\n}\n\nconst CurrencyDisplay: ForwardRefForwardPropsComponent<CurrencyDisplayProps> = forwardRef(\n function CurrencyDisplay(\n {\n value,\n currencyISOCode,\n formattingOptions: {\n currency = 'symbol',\n negative = 'minus-sign',\n notation = 'standard',\n groupSeparators = true,\n fractionDigits\n } = {},\n ...restProps\n }: PropsWithoutRef<CurrencyDisplayProps>,\n ref: CurrencyDisplayProps['ref']\n ) {\n const { locale } = useConfiguration();\n\n const options =\n currencyISOCode && isValidCurrency(currencyISOCode)\n ? ({\n style: 'currency',\n currency: currencyISOCode,\n currencyDisplay: currency,\n useGrouping: groupSeparators,\n notation,\n currencySign: negative === 'parentheses' ? 'accounting' : 'standard',\n minimumFractionDigits: fractionDigits,\n maximumFractionDigits: fractionDigits\n } as Intl.NumberFormatOptions)\n : undefined;\n\n const srOptions = {\n ...options,\n useGrouping: false,\n currencySign: 'standard',\n currencyDisplay: 'name'\n } satisfies Intl.NumberFormatOptions;\n\n return (\n <span ref={ref} {...restProps}>\n {value || value === 0 ? (\n <>\n <span aria-hidden>{formatCurrency(value, { locale, options })}</span>\n <VisuallyHiddenText>\n {formatCurrency(value, { locale, options: srOptions })}\n </VisuallyHiddenText>\n </>\n ) : (\n <NoValue />\n )}\n </span>\n );\n }\n);\n\nexport default CurrencyDisplay;\n"]}
1
+ {"version":3,"file":"CurrencyDisplay.js","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyDisplay.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAI5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,kBAAkB,MAAM,uBAAuB,CAAC;AACvD,OAAO,OAAO,MAAM,oBAAoB,CAAC;AAEzC,OAAO,EAAE,cAAc,EAAE,gCAAgC,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAkC5F,MAAM,eAAe,GAA0D,UAAU,CACvF,SAAS,eAAe,CACtB,EACE,KAAK,EACL,eAAe,EACf,iBAAiB,EAAE,EACjB,QAAQ,GAAG,QAAQ,EACnB,QAAQ,GAAG,YAAY,EACvB,QAAQ,GAAG,UAAU,EACrB,eAAe,GAAG,IAAI,EACtB,cAAc,EACf,GAAG,EAAE,EACN,GAAG,SAAS,EAC0B,EACxC,GAAgC;IAEhC,MAAM,EAAE,MAAM,EAAE,GAAG,gBAAgB,EAAE,CAAC;IAEtC,MAAM,oBAAoB,GAAG,OAAO,CAClC,GAAG,EAAE,CAAC,CAAC,eAAe,IAAI,eAAe,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,EACzF,CAAC,eAAe,CAAC,CAClB,CAAC;IAEF,MAAM,6BAA6B,GAAG,OAAO;IAC3C,iFAAiF;IACjF,iFAAiF;IACjF,4EAA4E;IAC5E,GAAG,EAAE,CACH,QAAQ,KAAK,UAAU;QACrB,CAAC,CAAC,gCAAgC,CAAC,MAAM,EAAE,oBAAoB,CAAC;QAChE,CAAC,CAAC,SAAS,EACf,CAAC,MAAM,EAAE,oBAAoB,EAAE,QAAQ,CAAC,CACzC,CAAC;IAEF,MAAM,OAAO,GAAG,oBAAoB;QAClC,CAAC,CAAE;YACC,KAAK,EAAE,UAAU;YACjB,QAAQ,EAAE,eAAe;YACzB,eAAe,EAAE,QAAQ;YACzB,WAAW,EAAE,eAAe;YAC5B,QAAQ;YACR,YAAY,EAAE,QAAQ,KAAK,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU;YACpE,qBAAqB,EAAE,cAAc,IAAI,6BAA6B;YACtE,qBAAqB,EAAE,cAAc,IAAI,6BAA6B;SACnC;QACvC,CAAC,CAAC,SAAS,CAAC;IAEd,MAAM,SAAS,GAAG;QAChB,GAAG,OAAO;QACV,WAAW,EAAE,KAAK;QAClB,YAAY,EAAE,UAAU;QACxB,eAAe,EAAE,MAAM;KACW,CAAC;IAErC,OAAO,CACL,eAAM,GAAG,EAAE,GAAG,KAAM,SAAS,YAC1B,KAAK,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CACtB,8BACE,8CAAmB,cAAc,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAQ,EACrE,KAAC,kBAAkB,cAChB,cAAc,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,GACnC,IACpB,CACJ,CAAC,CAAC,CAAC,CACF,KAAC,OAAO,KAAG,CACZ,GACI,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { forwardRef, useMemo } from 'react';\nimport type { PropsWithoutRef, Ref } from 'react';\n\nimport type { BaseProps, ForwardRefForwardPropsComponent, NoChildrenProp } from '../../types';\nimport { useConfiguration } from '../../hooks';\nimport VisuallyHiddenText from '../VisuallyHiddenText';\nimport NoValue from '../NoValue/NoValue';\n\nimport { formatCurrency, getCurrencyMinimumFractionDigits, isValidCurrency } from './utils';\n\nexport interface CurrencyDisplayProps extends BaseProps, NoChildrenProp {\n /** Number value. */\n value?: number | bigint;\n /** Three letter currency shorthand ISO code. If not provided or invalid, component renders only the number. */\n currencyISOCode?: string;\n /** Options to define formatting. */\n formattingOptions?: {\n currency?: 'symbol' | 'code' | 'name';\n /**\n * Determines negative value notation: using minus sign or parentheses.\n * @default 'minus-sign'\n */\n negative?: 'minus-sign' | 'parentheses';\n /**\n * Value display notation.\n * @default 'standard'\n */\n notation?: 'standard' | 'compact';\n /**\n * Fixed number of fraction digits. Maximum is 20, default is currency dependant.\n * @default variable\n */\n fractionDigits?: number;\n /** Determines whether group separators should be shown.\n * @default true\n */\n groupSeparators?: boolean;\n };\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLAnchorElement>;\n}\n\nconst CurrencyDisplay: ForwardRefForwardPropsComponent<CurrencyDisplayProps> = forwardRef(\n function CurrencyDisplay(\n {\n value,\n currencyISOCode,\n formattingOptions: {\n currency = 'symbol',\n negative = 'minus-sign',\n notation = 'standard',\n groupSeparators = true,\n fractionDigits\n } = {},\n ...restProps\n }: PropsWithoutRef<CurrencyDisplayProps>,\n ref: CurrencyDisplayProps['ref']\n ) {\n const { locale } = useConfiguration();\n\n const validCurrencyISOCode = useMemo(\n () => (currencyISOCode && isValidCurrency(currencyISOCode) ? currencyISOCode : undefined),\n [currencyISOCode]\n );\n\n const minimumCurrencyFractionDigits = useMemo(\n // Only relevant for 'standard' notation: 'compact' notation relies on Intl's own\n // rounding to a small number of significant digits, which a fixed fraction digit\n // count would defeat (e.g. preventing 999.99 from being abbreviated to 1K).\n () =>\n notation === 'standard'\n ? getCurrencyMinimumFractionDigits(locale, validCurrencyISOCode)\n : undefined,\n [locale, validCurrencyISOCode, notation]\n );\n\n const options = validCurrencyISOCode\n ? ({\n style: 'currency',\n currency: currencyISOCode,\n currencyDisplay: currency,\n useGrouping: groupSeparators,\n notation,\n currencySign: negative === 'parentheses' ? 'accounting' : 'standard',\n minimumFractionDigits: fractionDigits ?? minimumCurrencyFractionDigits,\n maximumFractionDigits: fractionDigits ?? minimumCurrencyFractionDigits\n } satisfies Intl.NumberFormatOptions)\n : undefined;\n\n const srOptions = {\n ...options,\n useGrouping: false,\n currencySign: 'standard',\n currencyDisplay: 'name'\n } satisfies Intl.NumberFormatOptions;\n\n return (\n <span ref={ref} {...restProps}>\n {value || value === 0 ? (\n <>\n <span aria-hidden>{formatCurrency(value, { locale, options })}</span>\n <VisuallyHiddenText>\n {formatCurrency(value, { locale, options: srOptions })}\n </VisuallyHiddenText>\n </>\n ) : (\n <NoValue />\n )}\n </span>\n );\n }\n);\n\nexport default CurrencyDisplay;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"DateTimeDisplay.d.ts","sourceRoot":"","sources":["../../../src/components/DateTime/DateTimeDisplay.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,GAAG,EAAE,MAAM,OAAO,CAAC;AAGlD,OAAO,KAAK,EAAE,SAAS,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAK9E,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAIjD,MAAM,WAAW,oBAAqB,SAAQ,SAAS;IACrD,+DAA+D;IAC/D,KAAK,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;IAC/B,kCAAkC;IAClC,OAAO,EAAE,eAAe,CAAC;IACzB;;;OAGG;IACH,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,8DAA8D;IAC9D,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC,eAAe,CAAC,CAAC;CAC5B;AAED,eAAO,MAAM,qBAAqB,mOAAgB,CAAC;AAEnD,QAAA,MAAM,eAAe,EAAE,+BAA+B,CAAC,oBAAoB,CAqE1E,CAAC;AAEF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"DateTimeDisplay.d.ts","sourceRoot":"","sources":["../../../src/components/DateTime/DateTimeDisplay.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,GAAG,EAAE,MAAM,OAAO,CAAC;AAGlD,OAAO,KAAK,EAAE,SAAS,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAK9E,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAIjD,MAAM,WAAW,oBAAqB,SAAQ,SAAS;IACrD,+DAA+D;IAC/D,KAAK,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;IAC/B,kCAAkC;IAClC,OAAO,EAAE,eAAe,CAAC;IACzB;;;OAGG;IACH,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,8DAA8D;IAC9D,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC,eAAe,CAAC,CAAC;CAC5B;AAED,eAAO,MAAM,qBAAqB,mOAAgB,CAAC;AAEnD,QAAA,MAAM,eAAe,EAAE,+BAA+B,CAAC,oBAAoB,CA+D1E,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -23,25 +23,19 @@ const DateTimeDisplay = forwardRef(function DateTimeDisplay({ value, variant, fo
23
23
  timeZone: 'UTC'
24
24
  }))
25
25
  : undefined;
26
- // Abbreviated month names (e.g. "Oct") read phonetically to screen readers, so an
27
- // accessible, fully expanded label (e.g. "October") is exposed via aria-label while
28
- // the visible, abbreviated text stays unchanged. Only 'medium' format ever renders an
29
- // abbreviated month name, so other formats simply reuse the display text.
30
- const accessibleText = hasValue && format === 'medium'
31
- ? cap(formatDateTime(parsedDate, {
32
- t,
33
- locale,
34
- format,
35
- variant,
36
- clockFormat,
37
- timeZone: 'UTC',
38
- abbreviated: false
39
- }))
40
- : displayText;
26
+ // 'medium' format may abbreviate the month (e.g. "Oct"), which reads phonetically to
27
+ // screen readers, so the fully expanded 'long' format is used as the accessible label.
41
28
  let content = _jsx(NoValue, {});
42
29
  if (hasValue) {
43
30
  content =
44
- displayText !== accessibleText ? (_jsx("abbr", { "aria-label": accessibleText, children: displayText })) : (_jsx(_Fragment, { children: displayText }));
31
+ format === 'medium' ? (_jsx("abbr", { "aria-label": formatDateTime(parsedDate, {
32
+ t,
33
+ locale,
34
+ variant,
35
+ clockFormat,
36
+ timeZone: 'UTC',
37
+ format: 'long'
38
+ }), children: displayText })) : (_jsx(_Fragment, { children: displayText }));
45
39
  }
46
40
  return (_jsx(StyledDateTimeDisplay, { ref: ref, dateTime: hasValue ? parsedDate.toISOString() : undefined, ...restProps, children: content }));
47
41
  });
@@ -1 +1 @@
1
- {"version":3,"file":"DateTimeDisplay.js","sourceRoot":"","sources":["../../../src/components/DateTime/DateTimeDisplay.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAGvC,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,OAAO,MAAM,oBAAoB,CAAC;AACzC,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAGlC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAkBzC,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,IAAI,CAAA,EAAE,CAAC;AAEnD,MAAM,eAAe,GAA0D,UAAU,CACvF,SAAS,eAAe,CACtB,EACE,KAAK,EACL,OAAO,EACP,MAAM,GAAG,QAAQ,EACjB,WAAW,EACX,GAAG,SAAS,EAC0B,EACxC,GAAgC;IAEhC,MAAM,EAAE,MAAM,EAAE,GAAG,gBAAgB,EAAE,CAAC;IACtC,MAAM,CAAC,GAAG,OAAO,EA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":["import { forwardRef } from 'react';\nimport type { PropsWithoutRef, Ref } from 'react';\nimport styled from 'styled-components';\n\nimport type { BaseProps, ForwardRefForwardPropsComponent } from '../../types';\nimport { useConfiguration, useI18n } from '../../hooks';\nimport NoValue from '../NoValue/NoValue';\nimport cap from '../../utils/cap';\n\nimport type { DateTimeFormat, DateTimeVariant } from './DateTime.types';\nimport { parseToDate } from './Input/utils';\nimport type { ClockFormat } from './Input/utils';\nimport { isValidDate } from './Picker/utils';\nimport { formatDateTime } from './utils';\n\nexport interface DateTimeDisplayProps extends BaseProps {\n /** Date as ISO8601 string, timestamp or native Date object. */\n value?: Date | string | number;\n /** Controls date time variant. */\n variant: DateTimeVariant;\n /**\n * Controls display format.\n * @default 'medium'\n */\n format?: DateTimeFormat;\n /** Defines clock format that overrides locale based format */\n clockFormat?: ClockFormat;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLTimeElement>;\n}\n\nexport const StyledDateTimeDisplay = styled.time``;\n\nconst DateTimeDisplay: ForwardRefForwardPropsComponent<DateTimeDisplayProps> = forwardRef(\n function DateTimeDisplay(\n {\n value,\n variant,\n format = 'medium',\n clockFormat,\n ...restProps\n }: PropsWithoutRef<DateTimeDisplayProps>,\n ref: DateTimeDisplayProps['ref']\n ) {\n const { locale } = useConfiguration();\n const t = useI18n();\n\n const parsedDate = value || value === 0 ? parseToDate(value) : undefined;\n const hasValue = !!parsedDate && isValidDate(parsedDate);\n\n const displayText = hasValue\n ? cap(\n formatDateTime(parsedDate, {\n t,\n locale,\n format,\n variant,\n clockFormat,\n timeZone: 'UTC'\n })\n )\n : undefined;\n\n // Abbreviated month names (e.g. \"Oct\") read phonetically to screen readers, so an\n // accessible, fully expanded label (e.g. \"October\") is exposed via aria-label while\n // the visible, abbreviated text stays unchanged. Only 'medium' format ever renders an\n // abbreviated month name, so other formats simply reuse the display text.\n const accessibleText =\n hasValue && format === 'medium'\n ? cap(\n formatDateTime(parsedDate, {\n t,\n locale,\n format,\n variant,\n clockFormat,\n timeZone: 'UTC',\n abbreviated: false\n })\n )\n : displayText;\n\n let content = <NoValue />;\n if (hasValue) {\n content =\n displayText !== accessibleText ? (\n <abbr aria-label={accessibleText}>{displayText}</abbr>\n ) : (\n <>{displayText}</>\n );\n }\n\n return (\n <StyledDateTimeDisplay\n ref={ref}\n dateTime={hasValue ? parsedDate.toISOString() : undefined}\n {...restProps}\n >\n {content}\n </StyledDateTimeDisplay>\n );\n }\n);\n\nexport default DateTimeDisplay;\n"]}
1
+ {"version":3,"file":"DateTimeDisplay.js","sourceRoot":"","sources":["../../../src/components/DateTime/DateTimeDisplay.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAGvC,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,OAAO,MAAM,oBAAoB,CAAC;AACzC,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAGlC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAkBzC,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,IAAI,CAAA,EAAE,CAAC;AAEnD,MAAM,eAAe,GAA0D,UAAU,CACvF,SAAS,eAAe,CACtB,EACE,KAAK,EACL,OAAO,EACP,MAAM,GAAG,QAAQ,EACjB,WAAW,EACX,GAAG,SAAS,EAC0B,EACxC,GAAgC;IAEhC,MAAM,EAAE,MAAM,EAAE,GAAG,gBAAgB,EAAE,CAAC;IACtC,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IAEpB,MAAM,UAAU,GAAG,KAAK,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACzE,MAAM,QAAQ,GAAG,CAAC,CAAC,UAAU,IAAI,WAAW,CAAC,UAAU,CAAC,CAAC;IAEzD,MAAM,WAAW,GAAG,QAAQ;QAC1B,CAAC,CAAC,GAAG,CACD,cAAc,CAAC,UAAU,EAAE;YACzB,CAAC;YACD,MAAM;YACN,MAAM;YACN,OAAO;YACP,WAAW;YACX,QAAQ,EAAE,KAAK;SAChB,CAAC,CACH;QACH,CAAC,CAAC,SAAS,CAAC;IAEd,qFAAqF;IACrF,uFAAuF;IACvF,IAAI,OAAO,GAAG,KAAC,OAAO,KAAG,CAAC;IAC1B,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO;YACL,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,CACpB,6BACc,cAAc,CAAC,UAAU,EAAE;oBACrC,CAAC;oBACD,MAAM;oBACN,OAAO;oBACP,WAAW;oBACX,QAAQ,EAAE,KAAK;oBACf,MAAM,EAAE,MAAM;iBACf,CAAC,YAED,WAAW,GACP,CACR,CAAC,CAAC,CAAC,CACF,4BAAG,WAAW,GAAI,CACnB,CAAC;IACN,CAAC;IAED,OAAO,CACL,KAAC,qBAAqB,IACpB,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS,KACrD,SAAS,YAEZ,OAAO,GACc,CACzB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { forwardRef } from 'react';\nimport type { PropsWithoutRef, Ref } from 'react';\nimport styled from 'styled-components';\n\nimport type { BaseProps, ForwardRefForwardPropsComponent } from '../../types';\nimport { useConfiguration, useI18n } from '../../hooks';\nimport NoValue from '../NoValue/NoValue';\nimport cap from '../../utils/cap';\n\nimport type { DateTimeFormat, DateTimeVariant } from './DateTime.types';\nimport { parseToDate } from './Input/utils';\nimport type { ClockFormat } from './Input/utils';\nimport { isValidDate } from './Picker/utils';\nimport { formatDateTime } from './utils';\n\nexport interface DateTimeDisplayProps extends BaseProps {\n /** Date as ISO8601 string, timestamp or native Date object. */\n value?: Date | string | number;\n /** Controls date time variant. */\n variant: DateTimeVariant;\n /**\n * Controls display format.\n * @default 'medium'\n */\n format?: DateTimeFormat;\n /** Defines clock format that overrides locale based format */\n clockFormat?: ClockFormat;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLTimeElement>;\n}\n\nexport const StyledDateTimeDisplay = styled.time``;\n\nconst DateTimeDisplay: ForwardRefForwardPropsComponent<DateTimeDisplayProps> = forwardRef(\n function DateTimeDisplay(\n {\n value,\n variant,\n format = 'medium',\n clockFormat,\n ...restProps\n }: PropsWithoutRef<DateTimeDisplayProps>,\n ref: DateTimeDisplayProps['ref']\n ) {\n const { locale } = useConfiguration();\n const t = useI18n();\n\n const parsedDate = value || value === 0 ? parseToDate(value) : undefined;\n const hasValue = !!parsedDate && isValidDate(parsedDate);\n\n const displayText = hasValue\n ? cap(\n formatDateTime(parsedDate, {\n t,\n locale,\n format,\n variant,\n clockFormat,\n timeZone: 'UTC'\n })\n )\n : undefined;\n\n // 'medium' format may abbreviate the month (e.g. \"Oct\"), which reads phonetically to\n // screen readers, so the fully expanded 'long' format is used as the accessible label.\n let content = <NoValue />;\n if (hasValue) {\n content =\n format === 'medium' ? (\n <abbr\n aria-label={formatDateTime(parsedDate, {\n t,\n locale,\n variant,\n clockFormat,\n timeZone: 'UTC',\n format: 'long'\n })}\n >\n {displayText}\n </abbr>\n ) : (\n <>{displayText}</>\n );\n }\n\n return (\n <StyledDateTimeDisplay\n ref={ref}\n dateTime={hasValue ? parsedDate.toISOString() : undefined}\n {...restProps}\n >\n {content}\n </StyledDateTimeDisplay>\n );\n }\n);\n\nexport default DateTimeDisplay;\n"]}
@@ -9,18 +9,7 @@ type DateTimeFormatOptions<F extends DateTimeFormat = DateTimeFormat> = {
9
9
  timeZone?: string;
10
10
  clockFormat?: ClockFormat;
11
11
  calendarType?: CalendarType;
12
- } & (F extends 'medium' ? {
13
- /**
14
- * When false, abbreviated month names (e.g. "Oct") are expanded to their full form
15
- * (e.g. "October") so the result is suitable for use as an accessible label read by
16
- * screen readers. Numeric months and locales without a distinct abbreviated form are
17
- * left untouched. Only has an effect when `format` is `'medium'`.
18
- * @default true
19
- */
20
- abbreviated?: boolean;
21
- } : {
22
- abbreviated?: never;
23
- }) & ({
12
+ } & ({
24
13
  variant: ExcludeStrict<DateTimeVariant, 'quarteryear'>;
25
14
  t?: TranslationFunction<TranslationPack>;
26
15
  } | {
@@ -28,7 +17,7 @@ type DateTimeFormatOptions<F extends DateTimeFormat = DateTimeFormat> = {
28
17
  t: TranslationFunction<TranslationPack>;
29
18
  });
30
19
  export declare function getIntlDateTimeFormatFromCache(locale: string, options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat;
31
- export declare function formatDateTime<F extends DateTimeFormat>(value: Date, { t, locale, format, variant, clockFormat, calendarType, timeZone, abbreviated }: DateTimeFormatOptions<F>): string;
20
+ export declare function formatDateTime<F extends DateTimeFormat>(value: Date, { t, locale, format, variant, clockFormat, calendarType, timeZone }: DateTimeFormatOptions<F>): string;
32
21
  interface DurationFormatOptions {
33
22
  /** Locale to be used - en_US, jp_JP, fr_FR etc */
34
23
  locale: string;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/DateTime/utils.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,OAAO,KAAK,EAAmB,cAAc,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACzF,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAQlE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAwBjD,KAAK,qBAAqB,CAAC,CAAC,SAAS,cAAc,GAAG,cAAc,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,cAAc,CAAC,CAAC,SAAS,cAAc,EACrD,KAAK,EAAE,IAAI,EACX,EACE,CAAC,EACD,MAAM,EACN,MAAM,EACN,OAAO,EACP,WAAW,EACX,YAAsC,EACtC,QAAQ,EACT,EAAE,qBAAqB,CAAC,CAAC,CAAC,UAqG5B;AAOD,UAAU,qBAAqB;IAC7B,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,gBAAgB,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACpC;;;OAGG;IACH,WAAW,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,CAAC;IACtD;;;OAGG;IACH,YAAY,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,aAAa,CAAC;CACrE;AAgBD,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,EACjB,EACE,MAAM,EACN,gBAAgB,EAChB,WAAsB,EACtB,YAAuB,EACxB,EAAE,qBAAqB,UAgCzB;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,QAAO,IAIzC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,GAAI,UAAU,MAAM,KAAG,IAQpE,CAAC"}
@@ -171,22 +171,7 @@ export function getIntlDateTimeFormatFromCache(locale, options = {}) {
171
171
  }
172
172
  const relativeTimeFormatCache = {};
173
173
  const displayNamesCache = {};
174
- // Expands any abbreviated 'month' part (e.g. "Oct") in the formatted parts of a date to
175
- // its full form (e.g. "October"), so the result can be exposed as an accessible label.
176
- // Numeric months and already-expanded month names are left untouched.
177
- function expandAbbreviatedMonthParts(date, parts, locale, timeZone) {
178
- return parts.map(part => {
179
- if (part.type !== 'month' || /^\d+$/.test(part.value)) {
180
- return part;
181
- }
182
- const longMonth = getIntlDateTimeFormatFromCache(locale, {
183
- month: 'long',
184
- timeZone
185
- }).format(date);
186
- return part.value === longMonth ? part : { ...part, value: longMonth };
187
- });
188
- }
189
- export function formatDateTime(value, { t, locale, format, variant, clockFormat, calendarType = CALENDAR_TYPES.ISO_8601, timeZone, abbreviated = true }) {
174
+ export function formatDateTime(value, { t, locale, format, variant, clockFormat, calendarType = CALENDAR_TYPES.ISO_8601, timeZone }) {
190
175
  const getFormattedDate = (date, dateVariant) => {
191
176
  const resolvedVariant = dateVariant === 'time' || dateVariant === 'datetime'
192
177
  ? `${dateVariant}${clockFormat ?? ''}`
@@ -196,12 +181,7 @@ export function formatDateTime(value, { t, locale, format, variant, clockFormat,
196
181
  ...resolvedOptions,
197
182
  timeZone
198
183
  });
199
- if (abbreviated) {
200
- return intlFormat.format(date);
201
- }
202
- return expandAbbreviatedMonthParts(date, intlFormat.formatToParts(date), locale, timeZone)
203
- .map(part => part.value)
204
- .join('');
184
+ return intlFormat.format(date);
205
185
  };
206
186
  const relativeTimeFormatter = (relativeValue, unit, enforceNumeric) => {
207
187
  const resolvedOptions = {
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/components/DateTime/utils.ts"],"names":[],"mappings":"AAAA,sBAAsB;AACtB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACvC,OAAO,GAAG,MAAM,kBAAkB,CAAC;AAInC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAGlC,OAAO,EAAE,cAAc,EAAqB,MAAM,eAAe,CAAC;AAClE,OAAO,EACL,YAAY,EACZ,yBAAyB,EACzB,cAAc,EACd,OAAO,EACP,WAAW,EACZ,MAAM,eAAe,CAAC;AAGvB,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAClB,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAEjB,MAAM,SAAS,GAAG;IAChB,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,GAAG,GAAG;IAC/B,KAAK,EAAE,CAAC,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IAC7D,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,QAAgB,EAAQ,EAAE;IAC1E,IAAI,CAAC;QACH,kCAAkC;QAClC,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;IACjD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,sBAAsB,EAAE,CAAC;IAClC,CAAC;IACD,OAAO,IAAI,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,yBAAyB,CAAC,GAAG,CAAC,CAAC;AAChF,CAAC,CAAC","sourcesContent":["// cspell:ignore DDTHH\nimport dayjs from 'dayjs';\nimport tz from 'dayjs/plugin/timezone';\nimport utc from 'dayjs/plugin/utc';\n\nimport type { TranslationFunction, TranslationPack } from '../../i18n';\nimport type { ExcludeStrict } from '../../types';\nimport { cap } from '../../utils';\n\nimport type { AbsoluteVariant, DateTimeFormat, DateTimeVariant } from './DateTime.types';\nimport { CALENDAR_TYPES, type CalendarType } from './Input/local';\nimport {\n getEndOfWeek,\n getQuarterForDateTimeZone,\n getStartOfWeek,\n getWeek,\n getWeekYear\n} from './Input/utils';\nimport type { ClockFormat } from './Input/utils';\n\ndayjs.extend(utc);\ndayjs.extend(tz);\n\nconst unitsInMs = {\n year: 24 * 60 * 60 * 1000 * 365,\n month: (24 * 60 * 60 * 1000 * 365) / 12,\n day: 24 * 60 * 60 * 1000,\n hour: 60 * 60 * 1000,\n minute: 60 * 1000,\n second: 1000\n} satisfies Partial<Record<Intl.RelativeTimeFormatUnit, number>>;\n\ntype TimeUnit = keyof typeof unitsInMs;\nconst timeUnitsOrdered = [\n 'year',\n 'month',\n 'day',\n 'hour',\n 'minute',\n 'second'\n] as const satisfies TimeUnit[];\n\ntype DateTimeFormatOptions<F extends DateTimeFormat = DateTimeFormat> = {\n locale: string;\n format: F;\n timeZone?: string;\n clockFormat?: ClockFormat;\n calendarType?: CalendarType;\n} & (F extends 'medium'\n ? {\n /**\n * When false, abbreviated month names (e.g. \"Oct\") are expanded to their full form\n * (e.g. \"October\") so the result is suitable for use as an accessible label read by\n * screen readers. Numeric months and locales without a distinct abbreviated form are\n * left untouched. Only has an effect when `format` is `'medium'`.\n * @default true\n */\n abbreviated?: boolean;\n }\n : { abbreviated?: never }) &\n (\n | {\n variant: ExcludeStrict<DateTimeVariant, 'quarteryear'>;\n t?: TranslationFunction<TranslationPack>;\n }\n | { variant: 'quarteryear'; t: TranslationFunction<TranslationPack> }\n );\n\ntype DateOptions = Pick<Intl.DateTimeFormatOptions, 'year' | 'month' | 'day'>;\ntype TimeOptions = Pick<Intl.DateTimeFormatOptions, 'hour' | 'minute' | 'second'>;\ntype DateStyle = Pick<Intl.DateTimeFormatOptions, 'dateStyle'>;\ntype TimeStyle = Pick<Intl.DateTimeFormatOptions, 'timeStyle'>;\n\nconst dateShort = {\n dateStyle: 'short'\n} satisfies DateStyle;\n\nconst dateMedium = {\n dateStyle: 'medium'\n} satisfies DateStyle;\n\nconst dateLong = {\n dateStyle: 'long'\n} satisfies DateStyle;\n\nconst dateNumeric = {\n year: 'numeric',\n month: 'numeric',\n day: 'numeric'\n} satisfies DateOptions;\n\nconst timeShort = {\n timeStyle: 'short'\n} satisfies TimeStyle;\n\nconst timeMedium = {\n timeStyle: 'medium'\n} satisfies TimeStyle;\n\nconst timeLong = {\n timeStyle: 'medium'\n} satisfies TimeStyle;\n\nconst timeNumeric = {\n hour: 'numeric',\n minute: 'numeric'\n} satisfies TimeOptions;\n\nconst dateTimeShort = {\n ...dateShort,\n ...timeShort\n} satisfies DateStyle & TimeStyle;\n\nconst dateTimeMedium = {\n ...dateMedium,\n ...timeShort\n} satisfies DateStyle & TimeStyle;\n\nconst dateTimeLong = {\n ...dateLong,\n ...timeMedium\n} satisfies DateStyle & TimeStyle;\n\nconst dateTimeNumeric = {\n ...dateNumeric,\n ...timeNumeric\n} satisfies DateOptions & TimeOptions;\n\nconst timeLongNumeric = {\n ...timeNumeric,\n second: 'numeric'\n} satisfies TimeOptions;\n\nconst dateTimeLongNumeric = {\n ...dateNumeric,\n ...timeLongNumeric\n} satisfies DateOptions & TimeOptions;\n\ntype AddClockFormatToTimeKeys<Key extends DateTimeVariant> = Key extends `${string}time`\n ? `${Key}${'' | 12 | 24}`\n : Key;\n\nconst formatMapping = {\n date: {\n short: dateShort,\n medium: dateMedium,\n long: dateLong,\n numeric: dateNumeric,\n 'long-numeric': dateNumeric\n },\n datetime: {\n short: dateTimeShort,\n medium: dateTimeMedium,\n long: dateTimeLong,\n numeric: dateTimeNumeric,\n 'long-numeric': dateTimeLongNumeric\n },\n datetime12: {\n short: { ...dateTimeShort, hour12: true },\n medium: { ...dateTimeMedium, hour12: true },\n long: { ...dateTimeLong, hour12: true },\n numeric: { ...dateTimeNumeric, hour12: true },\n 'long-numeric': { ...dateTimeLongNumeric, hour12: true }\n },\n datetime24: {\n short: { ...dateTimeShort, hour12: false },\n medium: { ...dateTimeMedium, hour12: false },\n long: { ...dateTimeLong, hour12: false },\n numeric: { ...dateTimeNumeric, hour12: false },\n 'long-numeric': { ...dateTimeLongNumeric, hour12: false }\n },\n time: {\n short: timeShort,\n medium: timeMedium,\n long: timeLong,\n numeric: timeNumeric,\n 'long-numeric': timeLongNumeric\n },\n time12: {\n short: { ...timeShort, hour12: true },\n medium: { ...timeMedium, hour12: true },\n long: { ...timeLong, hour12: true },\n numeric: { ...timeNumeric, hour12: true },\n 'long-numeric': { ...timeLongNumeric, hour12: true }\n },\n time24: {\n short: { ...timeShort, hour12: false },\n medium: { ...timeMedium, hour12: false },\n long: { ...timeLong, hour12: false },\n numeric: { ...timeNumeric, hour12: false },\n 'long-numeric': { ...timeLongNumeric, hour12: false }\n },\n month: {\n short: { month: 'short' },\n medium: { month: 'short' },\n long: { month: 'long' },\n numeric: { month: 'numeric' },\n 'long-numeric': { month: 'numeric' }\n },\n monthyear: {\n short: { year: 'numeric', month: 'short' },\n medium: { year: 'numeric', month: 'short' },\n long: { year: 'numeric', month: 'long' },\n numeric: { year: 'numeric', month: 'numeric' },\n 'long-numeric': { year: 'numeric', month: 'numeric' }\n },\n week: {\n short: { month: 'short', day: 'numeric' },\n medium: { month: 'short', day: 'numeric' },\n long: { month: 'long', day: 'numeric' },\n numeric: { month: 'numeric', day: 'numeric' },\n 'long-numeric': { month: 'numeric', day: 'numeric' }\n },\n year: {\n short: { year: 'numeric' },\n medium: { year: 'numeric' },\n long: { year: 'numeric' },\n numeric: { year: '2-digit' },\n 'long-numeric': { year: '2-digit' }\n },\n relative: {\n short: { style: 'long', numeric: 'auto' },\n medium: { style: 'long', numeric: 'auto' },\n long: { style: 'long', numeric: 'auto' },\n numeric: { style: 'short', numeric: 'auto' },\n 'long-numeric': { style: 'short', numeric: 'auto' }\n }\n} satisfies Record<\n AddClockFormatToTimeKeys<ExcludeStrict<AbsoluteVariant, 'quarteryear'>>,\n Record<DateTimeFormat, Intl.DateTimeFormatOptions>\n> &\n Record<'relative', Record<DateTimeFormat, Intl.RelativeTimeFormatOptions>>;\n\nconst dateTimeFormatCache: Map<\n // locale & stringified sorted Intl.DateTimeFormatOptions\n string,\n Intl.DateTimeFormat\n> = new Map();\n\nexport function getIntlDateTimeFormatFromCache(\n locale: string,\n options: Intl.DateTimeFormatOptions = {}\n) {\n const sortedOptions = JSON.stringify(options, Object.keys(options).sort());\n const key = `${locale}${sortedOptions}`;\n\n if (!dateTimeFormatCache.has(key)) {\n dateTimeFormatCache.set(key, new Intl.DateTimeFormat(locale, options));\n }\n\n return dateTimeFormatCache.get(key)!;\n}\n\nconst relativeTimeFormatCache: Record<\n // locale\n string,\n Map<Intl.RelativeTimeFormatOptions, Intl.RelativeTimeFormat>\n> = {};\n\nconst displayNamesCache: Record<\n // locale\n string,\n Intl.DateTimeDisplayNames\n> = {};\n\n// Expands any abbreviated 'month' part (e.g. \"Oct\") in the formatted parts of a date to\n// its full form (e.g. \"October\"), so the result can be exposed as an accessible label.\n// Numeric months and already-expanded month names are left untouched.\nfunction expandAbbreviatedMonthParts(\n date: Date,\n parts: Intl.DateTimeFormatPart[],\n locale: string,\n timeZone?: string\n): Intl.DateTimeFormatPart[] {\n return parts.map(part => {\n if (part.type !== 'month' || /^\\d+$/.test(part.value)) {\n return part;\n }\n\n const longMonth = getIntlDateTimeFormatFromCache(locale, {\n month: 'long',\n timeZone\n }).format(date);\n\n return part.value === longMonth ? part : { ...part, value: longMonth };\n });\n}\n\nexport function formatDateTime<F extends DateTimeFormat>(\n value: Date,\n {\n t,\n locale,\n format,\n variant,\n clockFormat,\n calendarType = CALENDAR_TYPES.ISO_8601,\n timeZone,\n abbreviated = true\n }: DateTimeFormatOptions<F>\n) {\n const getFormattedDate = (\n date: Date,\n dateVariant: ExcludeStrict<AbsoluteVariant, 'quarteryear'>\n ) => {\n const resolvedVariant: AddClockFormatToTimeKeys<typeof dateVariant> =\n dateVariant === 'time' || dateVariant === 'datetime'\n ? `${dateVariant}${clockFormat ?? ''}`\n : dateVariant;\n const resolvedOptions = formatMapping[resolvedVariant][format];\n\n const intlFormat = getIntlDateTimeFormatFromCache(locale, {\n ...resolvedOptions,\n timeZone\n });\n\n if (abbreviated) {\n return intlFormat.format(date);\n }\n\n return expandAbbreviatedMonthParts(date, intlFormat.formatToParts(date), locale, timeZone)\n .map(part => part.value)\n .join('');\n };\n\n const relativeTimeFormatter = (\n relativeValue: number,\n unit: TimeUnit,\n enforceNumeric?: boolean\n ) => {\n const resolvedOptions: Intl.RelativeTimeFormatOptions = {\n ...formatMapping.relative[format],\n numeric: enforceNumeric ? 'always' : 'auto'\n };\n\n relativeTimeFormatCache[locale] ??= new Map();\n const map = relativeTimeFormatCache[locale];\n\n if (!map.has(resolvedOptions)) {\n map.set(\n resolvedOptions,\n new Intl.RelativeTimeFormat(locale, {\n ...resolvedOptions\n })\n );\n }\n\n return map.get(resolvedOptions)!.format(relativeValue, unit);\n };\n\n const getRelativeTime = (date: Date) => {\n const now = dayjs();\n const targetDate = dayjs(date);\n\n // Deliberately reduce precision to 1 minute, handles \"now\" cases\n const isWithinMinute = Math.abs(targetDate.diff(now, 'millisecond')) < 60000;\n if (isWithinMinute) {\n return relativeTimeFormatter(0, 'second', false);\n }\n\n // Find the most appropriate unit by checking dayjs diff for each unit\n for (const unit of timeUnitsOrdered) {\n const diff = targetDate.diff(now, unit);\n if (Math.abs(diff) >= 1) {\n return relativeTimeFormatter(diff, unit, true);\n }\n }\n\n // Fallback to seconds if no unit has a difference >= 1\n const secondsDiff = targetDate.diff(now, 'second');\n return relativeTimeFormatter(secondsDiff, 'second', true);\n };\n\n const getFormattedWeek = (date: Date) => {\n displayNamesCache[locale] ??= new Intl.DisplayNames(locale, {\n style: 'long',\n type: 'dateTimeField'\n }) as Intl.DateTimeDisplayNames;\n\n const displayNames = displayNamesCache[locale];\n const startDate = getFormattedDate(getStartOfWeek(date, calendarType, timeZone), 'week');\n const endDate = getFormattedDate(getEndOfWeek(date, calendarType, timeZone), 'week');\n\n return `${cap(displayNames.of('weekOfYear'))} ${getWeek(\n date,\n calendarType,\n timeZone\n )}, ${getWeekYear(date, calendarType, timeZone)} (${startDate} - ${endDate})`;\n };\n\n const getFormattedQuarterYear = (date: Date) => {\n const formattedYear = getFormattedDate(date, 'year');\n const quarterNumber = getQuarterForDateTimeZone(date, timeZone);\n return `${t!(`date_quarter_q${quarterNumber}`, [formattedYear])}`;\n };\n\n switch (variant) {\n case 'relative':\n return getRelativeTime(value);\n case 'week':\n return getFormattedWeek(value);\n case 'quarteryear':\n return getFormattedQuarterYear(value);\n default:\n return getFormattedDate(value, variant);\n }\n}\n\nconst dayInMs = 24 * 60 * 60 * 1000;\nconst hourInMs = 60 * 60 * 1000;\nconst minuteInMs = 60 * 1000;\nconst secondInMs = 1000;\n\ninterface DurationFormatOptions {\n /** Locale to be used - en_US, jp_JP, fr_FR etc */\n locale: string;\n /** Determines maximum number of units to be displayed. */\n significantUnits: 5 | 4 | 3 | 2 | 1;\n /**\n * Unit formatting style\n * @default \"narrow\"\n */\n unitDisplay?: Intl.NumberFormatOptions['unitDisplay'];\n /**\n * Unit of maximum precision\n * @default \"second\"\n */\n maxPrecision?: 'day' | 'hour' | 'minute' | 'second' | 'millisecond';\n}\n\nconst numberFormatCache: Record<\n // locale\n string,\n Record<\n // unit\n string,\n Record<\n // unitDisplay\n string,\n Intl.NumberFormat\n >\n >\n> = {};\n\nexport function formatDuration(\n valueInMs: number,\n {\n locale,\n significantUnits,\n unitDisplay = 'narrow',\n maxPrecision = 'second'\n }: DurationFormatOptions\n) {\n numberFormatCache[locale] ??= {};\n\n const sign = valueInMs < 0 ? '-' : '';\n const absMs = Math.abs(valueInMs);\n\n const durationParts = [\n { unit: 'day', value: Math.floor(absMs / dayInMs) },\n { unit: 'hour', value: Math.floor((absMs % dayInMs) / hourInMs) },\n { unit: 'minute', value: Math.floor((absMs % hourInMs) / minuteInMs) },\n { unit: 'second', value: Math.floor((absMs % minuteInMs) / secondInMs) },\n { unit: 'millisecond', value: absMs % secondInMs }\n ];\n\n const result = [];\n for (let i = 0; result.length < significantUnits && i < durationParts.length; i += 1) {\n const { value, unit } = durationParts[i];\n\n if (value > 0 || (unit === maxPrecision && result.length === 0)) {\n numberFormatCache[locale][unit] ??= {};\n numberFormatCache[locale][unit][unitDisplay] ??= new Intl.NumberFormat(locale, {\n style: 'unit',\n unit,\n unitDisplay\n });\n\n result.push(numberFormatCache[locale][unit][unitDisplay].format(value));\n }\n if (durationParts[i].unit === maxPrecision) break;\n }\n return `${sign}${result.join(' ')}`;\n}\n\n/**\n * @returns Current date and time value adjusted for local time zone.\n */\nexport const getAdjustedUTCDateTime = (): Date => {\n const now = new Date();\n now.setTime(now.getTime() - now.getTimezoneOffset() * 60000);\n return now;\n};\n\n/**\n * @param timeZone - IANA timezone string (e.g. \"America/New_York\")\n * @returns Current date and time for the given timezone, with wall-clock time\n * encoded in UTC fields — matching the convention used by DateTime inputs.\n */\nexport const getAdjustedUTCDateTimeForTimezone = (timeZone: string): Date => {\n try {\n // eslint-disable-next-line no-new\n new Intl.DateTimeFormat('en-US', { timeZone });\n } catch {\n return getAdjustedUTCDateTime();\n }\n return new Date(`${dayjs().tz(timeZone).format('YYYY-MM-DDTHH:mm:ss.SSS')}Z`);\n};\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/components/DateTime/utils.ts"],"names":[],"mappings":"AAAA,sBAAsB;AACtB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACvC,OAAO,GAAG,MAAM,kBAAkB,CAAC;AAInC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAGlC,OAAO,EAAE,cAAc,EAAqB,MAAM,eAAe,CAAC;AAClE,OAAO,EACL,YAAY,EACZ,yBAAyB,EACzB,cAAc,EACd,OAAO,EACP,WAAW,EACZ,MAAM,eAAe,CAAC;AAGvB,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAClB,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAEjB,MAAM,SAAS,GAAG;IAChB,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,GAAG,GAAG;IAC/B,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,GAAG,GAAG,CAAC,GAAG,EAAE;IACvC,GAAG,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IACxB,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;IACpB,MAAM,EAAE,EAAE,GAAG,IAAI;IACjB,MAAM,EAAE,IAAI;CACkD,CAAC;AAGjE,MAAM,gBAAgB,GAAG;IACvB,MAAM;IACN,OAAO;IACP,KAAK;IACL,MAAM;IACN,QAAQ;IACR,QAAQ;CACqB,CAAC;AAqBhC,MAAM,SAAS,GAAG;IAChB,SAAS,EAAE,OAAO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MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,QAAgB,EAAQ,EAAE;IAC1E,IAAI,CAAC;QACH,kCAAkC;QAClC,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;IACjD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,sBAAsB,EAAE,CAAC;IAClC,CAAC;IACD,OAAO,IAAI,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,yBAAyB,CAAC,GAAG,CAAC,CAAC;AAChF,CAAC,CAAC","sourcesContent":["// cspell:ignore DDTHH\nimport dayjs from 'dayjs';\nimport tz from 'dayjs/plugin/timezone';\nimport utc from 'dayjs/plugin/utc';\n\nimport type { TranslationFunction, TranslationPack } from '../../i18n';\nimport type { ExcludeStrict } from '../../types';\nimport { cap } from '../../utils';\n\nimport type { AbsoluteVariant, DateTimeFormat, DateTimeVariant } from './DateTime.types';\nimport { CALENDAR_TYPES, type CalendarType } from './Input/local';\nimport {\n getEndOfWeek,\n getQuarterForDateTimeZone,\n getStartOfWeek,\n getWeek,\n getWeekYear\n} from './Input/utils';\nimport type { ClockFormat } from './Input/utils';\n\ndayjs.extend(utc);\ndayjs.extend(tz);\n\nconst unitsInMs = {\n year: 24 * 60 * 60 * 1000 * 365,\n month: (24 * 60 * 60 * 1000 * 365) / 12,\n day: 24 * 60 * 60 * 1000,\n hour: 60 * 60 * 1000,\n minute: 60 * 1000,\n second: 1000\n} satisfies Partial<Record<Intl.RelativeTimeFormatUnit, number>>;\n\ntype TimeUnit = keyof typeof unitsInMs;\nconst timeUnitsOrdered = [\n 'year',\n 'month',\n 'day',\n 'hour',\n 'minute',\n 'second'\n] as const satisfies TimeUnit[];\n\ntype DateTimeFormatOptions<F extends DateTimeFormat = DateTimeFormat> = {\n locale: string;\n format: F;\n timeZone?: string;\n clockFormat?: ClockFormat;\n calendarType?: CalendarType;\n} & (\n | {\n variant: ExcludeStrict<DateTimeVariant, 'quarteryear'>;\n t?: TranslationFunction<TranslationPack>;\n }\n | { variant: 'quarteryear'; t: TranslationFunction<TranslationPack> }\n);\n\ntype DateOptions = Pick<Intl.DateTimeFormatOptions, 'year' | 'month' | 'day'>;\ntype TimeOptions = Pick<Intl.DateTimeFormatOptions, 'hour' | 'minute' | 'second'>;\ntype DateStyle = Pick<Intl.DateTimeFormatOptions, 'dateStyle'>;\ntype TimeStyle = Pick<Intl.DateTimeFormatOptions, 'timeStyle'>;\n\nconst dateShort = {\n dateStyle: 'short'\n} satisfies DateStyle;\n\nconst dateMedium = {\n dateStyle: 'medium'\n} satisfies DateStyle;\n\nconst dateLong = {\n dateStyle: 'long'\n} satisfies DateStyle;\n\nconst dateNumeric = {\n year: 'numeric',\n month: 'numeric',\n day: 'numeric'\n} satisfies DateOptions;\n\nconst timeShort = {\n timeStyle: 'short'\n} satisfies TimeStyle;\n\nconst timeMedium = {\n timeStyle: 'medium'\n} satisfies TimeStyle;\n\nconst timeLong = {\n timeStyle: 'medium'\n} satisfies TimeStyle;\n\nconst timeNumeric = {\n hour: 'numeric',\n minute: 'numeric'\n} satisfies TimeOptions;\n\nconst dateTimeShort = {\n ...dateShort,\n ...timeShort\n} satisfies DateStyle & TimeStyle;\n\nconst dateTimeMedium = {\n ...dateMedium,\n ...timeShort\n} satisfies DateStyle & TimeStyle;\n\nconst dateTimeLong = {\n ...dateLong,\n ...timeMedium\n} satisfies DateStyle & TimeStyle;\n\nconst dateTimeNumeric = {\n ...dateNumeric,\n ...timeNumeric\n} satisfies DateOptions & TimeOptions;\n\nconst timeLongNumeric = {\n ...timeNumeric,\n second: 'numeric'\n} satisfies TimeOptions;\n\nconst dateTimeLongNumeric = {\n ...dateNumeric,\n ...timeLongNumeric\n} satisfies DateOptions & TimeOptions;\n\ntype AddClockFormatToTimeKeys<Key extends DateTimeVariant> = Key extends `${string}time`\n ? `${Key}${'' | 12 | 24}`\n : Key;\n\nconst formatMapping = {\n date: {\n short: dateShort,\n medium: dateMedium,\n long: dateLong,\n numeric: dateNumeric,\n 'long-numeric': dateNumeric\n },\n datetime: {\n short: dateTimeShort,\n medium: dateTimeMedium,\n long: dateTimeLong,\n numeric: dateTimeNumeric,\n 'long-numeric': dateTimeLongNumeric\n },\n datetime12: {\n short: { ...dateTimeShort, hour12: true },\n medium: { ...dateTimeMedium, hour12: true },\n long: { ...dateTimeLong, hour12: true },\n numeric: { ...dateTimeNumeric, hour12: true },\n 'long-numeric': { ...dateTimeLongNumeric, hour12: true }\n },\n datetime24: {\n short: { ...dateTimeShort, hour12: false },\n medium: { ...dateTimeMedium, hour12: false },\n long: { ...dateTimeLong, hour12: false },\n numeric: { ...dateTimeNumeric, hour12: false },\n 'long-numeric': { ...dateTimeLongNumeric, hour12: false }\n },\n time: {\n short: timeShort,\n medium: timeMedium,\n long: timeLong,\n numeric: timeNumeric,\n 'long-numeric': timeLongNumeric\n },\n time12: {\n short: { ...timeShort, hour12: true },\n medium: { ...timeMedium, hour12: true },\n long: { ...timeLong, hour12: true },\n numeric: { ...timeNumeric, hour12: true },\n 'long-numeric': { ...timeLongNumeric, hour12: true }\n },\n time24: {\n short: { ...timeShort, hour12: false },\n medium: { ...timeMedium, hour12: false },\n long: { ...timeLong, hour12: false },\n numeric: { ...timeNumeric, hour12: false },\n 'long-numeric': { ...timeLongNumeric, hour12: false }\n },\n month: {\n short: { month: 'short' },\n medium: { month: 'short' },\n long: { month: 'long' },\n numeric: { month: 'numeric' },\n 'long-numeric': { month: 'numeric' }\n },\n monthyear: {\n short: { year: 'numeric', month: 'short' },\n medium: { year: 'numeric', month: 'short' },\n long: { year: 'numeric', month: 'long' },\n numeric: { year: 'numeric', month: 'numeric' },\n 'long-numeric': { year: 'numeric', month: 'numeric' }\n },\n week: {\n short: { month: 'short', day: 'numeric' },\n medium: { month: 'short', day: 'numeric' },\n long: { month: 'long', day: 'numeric' },\n numeric: { month: 'numeric', day: 'numeric' },\n 'long-numeric': { month: 'numeric', day: 'numeric' }\n },\n year: {\n short: { year: 'numeric' },\n medium: { year: 'numeric' },\n long: { year: 'numeric' },\n numeric: { year: '2-digit' },\n 'long-numeric': { year: '2-digit' }\n },\n relative: {\n short: { style: 'long', numeric: 'auto' },\n medium: { style: 'long', numeric: 'auto' },\n long: { style: 'long', numeric: 'auto' },\n numeric: { style: 'short', numeric: 'auto' },\n 'long-numeric': { style: 'short', numeric: 'auto' }\n }\n} satisfies Record<\n AddClockFormatToTimeKeys<ExcludeStrict<AbsoluteVariant, 'quarteryear'>>,\n Record<DateTimeFormat, Intl.DateTimeFormatOptions>\n> &\n Record<'relative', Record<DateTimeFormat, Intl.RelativeTimeFormatOptions>>;\n\nconst dateTimeFormatCache: Map<\n // locale & stringified sorted Intl.DateTimeFormatOptions\n string,\n Intl.DateTimeFormat\n> = new Map();\n\nexport function getIntlDateTimeFormatFromCache(\n locale: string,\n options: Intl.DateTimeFormatOptions = {}\n) {\n const sortedOptions = JSON.stringify(options, Object.keys(options).sort());\n const key = `${locale}${sortedOptions}`;\n\n if (!dateTimeFormatCache.has(key)) {\n dateTimeFormatCache.set(key, new Intl.DateTimeFormat(locale, options));\n }\n\n return dateTimeFormatCache.get(key)!;\n}\n\nconst relativeTimeFormatCache: Record<\n // locale\n string,\n Map<Intl.RelativeTimeFormatOptions, Intl.RelativeTimeFormat>\n> = {};\n\nconst displayNamesCache: Record<\n // locale\n string,\n Intl.DateTimeDisplayNames\n> = {};\n\nexport function formatDateTime<F extends DateTimeFormat>(\n value: Date,\n {\n t,\n locale,\n format,\n variant,\n clockFormat,\n calendarType = CALENDAR_TYPES.ISO_8601,\n timeZone\n }: DateTimeFormatOptions<F>\n) {\n const getFormattedDate = (\n date: Date,\n dateVariant: ExcludeStrict<AbsoluteVariant, 'quarteryear'>\n ) => {\n const resolvedVariant: AddClockFormatToTimeKeys<typeof dateVariant> =\n dateVariant === 'time' || dateVariant === 'datetime'\n ? `${dateVariant}${clockFormat ?? ''}`\n : dateVariant;\n const resolvedOptions = formatMapping[resolvedVariant][format];\n\n const intlFormat = getIntlDateTimeFormatFromCache(locale, {\n ...resolvedOptions,\n timeZone\n });\n\n return intlFormat.format(date);\n };\n\n const relativeTimeFormatter = (\n relativeValue: number,\n unit: TimeUnit,\n enforceNumeric?: boolean\n ) => {\n const resolvedOptions: Intl.RelativeTimeFormatOptions = {\n ...formatMapping.relative[format],\n numeric: enforceNumeric ? 'always' : 'auto'\n };\n\n relativeTimeFormatCache[locale] ??= new Map();\n const map = relativeTimeFormatCache[locale];\n\n if (!map.has(resolvedOptions)) {\n map.set(\n resolvedOptions,\n new Intl.RelativeTimeFormat(locale, {\n ...resolvedOptions\n })\n );\n }\n\n return map.get(resolvedOptions)!.format(relativeValue, unit);\n };\n\n const getRelativeTime = (date: Date) => {\n const now = dayjs();\n const targetDate = dayjs(date);\n\n // Deliberately reduce precision to 1 minute, handles \"now\" cases\n const isWithinMinute = Math.abs(targetDate.diff(now, 'millisecond')) < 60000;\n if (isWithinMinute) {\n return relativeTimeFormatter(0, 'second', false);\n }\n\n // Find the most appropriate unit by checking dayjs diff for each unit\n for (const unit of timeUnitsOrdered) {\n const diff = targetDate.diff(now, unit);\n if (Math.abs(diff) >= 1) {\n return relativeTimeFormatter(diff, unit, true);\n }\n }\n\n // Fallback to seconds if no unit has a difference >= 1\n const secondsDiff = targetDate.diff(now, 'second');\n return relativeTimeFormatter(secondsDiff, 'second', true);\n };\n\n const getFormattedWeek = (date: Date) => {\n displayNamesCache[locale] ??= new Intl.DisplayNames(locale, {\n style: 'long',\n type: 'dateTimeField'\n }) as Intl.DateTimeDisplayNames;\n\n const displayNames = displayNamesCache[locale];\n const startDate = getFormattedDate(getStartOfWeek(date, calendarType, timeZone), 'week');\n const endDate = getFormattedDate(getEndOfWeek(date, calendarType, timeZone), 'week');\n\n return `${cap(displayNames.of('weekOfYear'))} ${getWeek(\n date,\n calendarType,\n timeZone\n )}, ${getWeekYear(date, calendarType, timeZone)} (${startDate} - ${endDate})`;\n };\n\n const getFormattedQuarterYear = (date: Date) => {\n const formattedYear = getFormattedDate(date, 'year');\n const quarterNumber = getQuarterForDateTimeZone(date, timeZone);\n return `${t!(`date_quarter_q${quarterNumber}`, [formattedYear])}`;\n };\n\n switch (variant) {\n case 'relative':\n return getRelativeTime(value);\n case 'week':\n return getFormattedWeek(value);\n case 'quarteryear':\n return getFormattedQuarterYear(value);\n default:\n return getFormattedDate(value, variant);\n }\n}\n\nconst dayInMs = 24 * 60 * 60 * 1000;\nconst hourInMs = 60 * 60 * 1000;\nconst minuteInMs = 60 * 1000;\nconst secondInMs = 1000;\n\ninterface DurationFormatOptions {\n /** Locale to be used - en_US, jp_JP, fr_FR etc */\n locale: string;\n /** Determines maximum number of units to be displayed. */\n significantUnits: 5 | 4 | 3 | 2 | 1;\n /**\n * Unit formatting style\n * @default \"narrow\"\n */\n unitDisplay?: Intl.NumberFormatOptions['unitDisplay'];\n /**\n * Unit of maximum precision\n * @default \"second\"\n */\n maxPrecision?: 'day' | 'hour' | 'minute' | 'second' | 'millisecond';\n}\n\nconst numberFormatCache: Record<\n // locale\n string,\n Record<\n // unit\n string,\n Record<\n // unitDisplay\n string,\n Intl.NumberFormat\n >\n >\n> = {};\n\nexport function formatDuration(\n valueInMs: number,\n {\n locale,\n significantUnits,\n unitDisplay = 'narrow',\n maxPrecision = 'second'\n }: DurationFormatOptions\n) {\n numberFormatCache[locale] ??= {};\n\n const sign = valueInMs < 0 ? '-' : '';\n const absMs = Math.abs(valueInMs);\n\n const durationParts = [\n { unit: 'day', value: Math.floor(absMs / dayInMs) },\n { unit: 'hour', value: Math.floor((absMs % dayInMs) / hourInMs) },\n { unit: 'minute', value: Math.floor((absMs % hourInMs) / minuteInMs) },\n { unit: 'second', value: Math.floor((absMs % minuteInMs) / secondInMs) },\n { unit: 'millisecond', value: absMs % secondInMs }\n ];\n\n const result = [];\n for (let i = 0; result.length < significantUnits && i < durationParts.length; i += 1) {\n const { value, unit } = durationParts[i];\n\n if (value > 0 || (unit === maxPrecision && result.length === 0)) {\n numberFormatCache[locale][unit] ??= {};\n numberFormatCache[locale][unit][unitDisplay] ??= new Intl.NumberFormat(locale, {\n style: 'unit',\n unit,\n unitDisplay\n });\n\n result.push(numberFormatCache[locale][unit][unitDisplay].format(value));\n }\n if (durationParts[i].unit === maxPrecision) break;\n }\n return `${sign}${result.join(' ')}`;\n}\n\n/**\n * @returns Current date and time value adjusted for local time zone.\n */\nexport const getAdjustedUTCDateTime = (): Date => {\n const now = new Date();\n now.setTime(now.getTime() - now.getTimezoneOffset() * 60000);\n return now;\n};\n\n/**\n * @param timeZone - IANA timezone string (e.g. \"America/New_York\")\n * @returns Current date and time for the given timezone, with wall-clock time\n * encoded in UTC fields — matching the convention used by DateTime inputs.\n */\nexport const getAdjustedUTCDateTimeForTimezone = (timeZone: string): Date => {\n try {\n // eslint-disable-next-line no-new\n new Intl.DateTimeFormat('en-US', { timeZone });\n } catch {\n return getAdjustedUTCDateTime();\n }\n return new Date(`${dayjs().tz(timeZone).format('YYYY-MM-DDTHH:mm:ss.SSS')}Z`);\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pega/cosmos-react-core",
3
- "version": "9.23.1",
3
+ "version": "9.23.3",
4
4
  "description": "Cosmos is a visual design system and UI component collection. Its goal is to empower application developers in their pursuit to create engaging and rewarding user experiences.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Pegasystems",