-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(i18n): add
useIntlDateTimeFormat
hook
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
packages/sanity/src/core/i18n/hooks/useIntlDateTimeFormat.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {intlCache} from '../intlCache' | ||
import {useCurrentLocale} from './useLocale' | ||
|
||
/** | ||
* Options for the `useIntlDateTimeFormat` hook | ||
* | ||
* @public | ||
*/ | ||
export type UseIntlDateTimeFormatOptions = Omit< | ||
Intl.DateTimeFormatOptions, | ||
'fractionalSecondDigits' | ||
> | ||
|
||
/** | ||
* Returns an instance of `Intl.DateTimeFormat` that uses the currently selected locale, | ||
* and enables locale and culture-sensitive date formatting. | ||
* | ||
* @param options - Optional options for the date/time formatter | ||
* @returns Instance of `Intl.DateTimeFormat` | ||
* @public | ||
*/ | ||
export function useIntlDateTimeFormat( | ||
options: UseIntlDateTimeFormatOptions = {}, | ||
): Intl.DateTimeFormat { | ||
const currentLocale = useCurrentLocale() | ||
return intlCache.dateTimeFormat(currentLocale, options) | ||
} |