update cloudflare context
This commit is contained in:
33
packages/ui/src/components/datetime.tsx
Normal file
33
packages/ui/src/components/datetime.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import type { ComponentPropsWithoutRef } from 'react'
|
||||
|
||||
type DateTimeProps = {
|
||||
children: string
|
||||
options?: Intl.DateTimeFormatOptions
|
||||
locale?: string
|
||||
} & ComponentPropsWithoutRef<'time'>
|
||||
|
||||
export function DateTime({
|
||||
children,
|
||||
options,
|
||||
locale = 'pt-BR',
|
||||
...props
|
||||
}: DateTimeProps) {
|
||||
const optionsInit: Intl.DateTimeFormatOptions = {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
}
|
||||
|
||||
const datetime = new Intl.DateTimeFormat(locale, {
|
||||
...optionsInit,
|
||||
...options
|
||||
})
|
||||
|
||||
return (
|
||||
<time dateTime={children} {...props}>
|
||||
{datetime.format(new Date(children))}
|
||||
</time>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user