Skip to content

Commit 0aa5cb8

Browse files
NotWoodsMs2ger
authored andcommitted
Add types for Intl
1 parent 134b2e2 commit 0aa5cb8

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

polyfill/index.d.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,3 +1637,79 @@ export namespace Temporal {
16371637
export function timeZone(): Temporal.TimeZone;
16381638
}
16391639
}
1640+
1641+
declare namespace IntlPolyfill {
1642+
type Formattable =
1643+
| Date
1644+
| Temporal.Instant
1645+
| Temporal.ZonedDateTime
1646+
| Temporal.PlainDate
1647+
| Temporal.PlainTime
1648+
| Temporal.PlainDateTime
1649+
| Temporal.PlainYearMonth
1650+
| Temporal.PlainMonthDay;
1651+
1652+
interface DateTimeFormatRangePart extends Intl.DateTimeFormatPart {
1653+
source: 'shared' | 'startRange' | 'endRange';
1654+
}
1655+
1656+
export interface DateTimeFormat extends Intl.DateTimeFormat {
1657+
/**
1658+
* Format a date into a string according to the locale and formatting
1659+
* options of this `Intl.DateTimeFormat` object.
1660+
*
1661+
* @param date The date to format.
1662+
*/
1663+
format(date?: Formattable | number): string;
1664+
1665+
/**
1666+
* Allow locale-aware formatting of strings produced by
1667+
* `Intl.DateTimeFormat` formatters.
1668+
*
1669+
* @param date The date to format.
1670+
*/
1671+
formatToParts(date?: Formattable | number): Intl.DateTimeFormatPart[];
1672+
1673+
/**
1674+
* Format a date range in the most concise way based on the locale and
1675+
* options provided when instantiating this `Intl.DateTimeFormat` object.
1676+
*
1677+
* @param startDate The start date of the range to format.
1678+
* @param endDate The start date of the range to format. Must be the same
1679+
* type as `startRange`.
1680+
*/
1681+
formatRange<T extends Formattable>(startDate: T, endDate: T): string;
1682+
formatRange(startDate: Date | number, endDate: Date | number): string;
1683+
1684+
/**
1685+
* Allow locale-aware formatting of tokens representing each part of the
1686+
* formatted date range produced by `Intl.DateTimeFormat` formatters.
1687+
*
1688+
* @param startDate The start date of the range to format.
1689+
* @param endDate The start date of the range to format. Must be the same
1690+
* type as `startRange`.
1691+
*/
1692+
formatRangeToParts<T extends Formattable>(startDate: T, endDate: T): DateTimeFormatRangePart[];
1693+
formatRangeToParts(startDate: Date | number, endDate: Date | number): DateTimeFormatRangePart[];
1694+
}
1695+
1696+
export const DateTimeFormat: {
1697+
/**
1698+
* Creates `Intl.DateTimeFormat` objects that enable language-sensitive
1699+
* date and time formatting.
1700+
*/
1701+
new (locales?: string | string[], options?: Intl.DateTimeFormatOptions): DateTimeFormat;
1702+
(locales?: string | string[], options?: Intl.DateTimeFormatOptions): DateTimeFormat;
1703+
1704+
/**
1705+
* Get an array containing those of the provided locales that are supported
1706+
* in date and time formatting without having to fall back to the runtime's
1707+
* default locale.
1708+
*/
1709+
supportedLocalesOf(locales: string | string[], options?: Intl.DateTimeFormatOptions): string[];
1710+
};
1711+
}
1712+
1713+
export { IntlPolyfill as Intl };
1714+
1715+
export function toTemporalInstant(this: Date): Temporal.Instant;

0 commit comments

Comments
 (0)