MCPcopy Create free account
hub / github.com/adobe/react-spectrum / FormattedDate

Function FormattedDate

packages/@react-spectrum/s2/src/LabeledValue.tsx:288–311  ·  view source on GitHub ↗
({
  value,
  formatOptions
}: {
  value: T;
  formatOptions?: Intl.DateTimeFormatOptions;
})

Source from the content-addressed store, hash-verified

286}
287
288function 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
313function convertDateTime(value: DateTime, timeZone: string): Date {
314 if ('timeZone' in value) {

Callers

nothing calls this directly

Calls 7

useDateFormatterFunction · 0.90
getLocalTimeZoneFunction · 0.90
getDefaultFormatOptionsFunction · 0.70
convertDateTimeFunction · 0.70
resolvedOptionsMethod · 0.45
formatRangeMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected