Skip to content

Commit

Permalink
feat(i18n): add useIntlDateTimeFormat hook
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Nov 3, 2023
1 parent 34b935c commit 1e5e4b0
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/sanity/src/core/i18n/hooks/useIntlDateTimeFormat.ts
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)
}

0 comments on commit 1e5e4b0

Please sign in to comment.