({
value,
formatOptions
}: {
value: T;
formatOptions?: Intl.DateTimeFormatOptions;
})
| 286 | } |
| 287 | |
| 288 | function FormattedDate<T extends DateTimeValue>({ |
| 289 | value, |
| 290 | formatOptions |
| 291 | }: { |
| 292 | value: T; |
| 293 | formatOptions?: Intl.DateTimeFormatOptions; |
| 294 | }) { |
| 295 | if (!formatOptions) { |
| 296 | formatOptions = getDefaultFormatOptions( |
| 297 | 'start' in value ? (value as RangeDateTime).start : (value as DateTime) |
| 298 | ); |
| 299 | } |
| 300 | |
| 301 | let dateFormatter = useDateFormatter(formatOptions); |
| 302 | let timeZone = dateFormatter.resolvedOptions().timeZone || getLocalTimeZone(); |
| 303 | |
| 304 | if ('start' in value && 'end' in value) { |
| 305 | let start = convertDateTime((value as RangeDateTime).start, timeZone); |
| 306 | let end = convertDateTime((value as RangeDateTime).end, timeZone); |
| 307 | return <>{dateFormatter.formatRange(start, end)}</>; |
| 308 | } |
| 309 | |
| 310 | return <>{dateFormatter.format(convertDateTime(value as DateTime, timeZone))}</>; |
| 311 | } |
| 312 | |
| 313 | function convertDateTime(value: DateTime, timeZone: string): Date { |
| 314 | if ('timeZone' in value) { |
nothing calls this directly
no test coverage detected