Skip to content

Support Temporal type in @internationalized/date DateFormatter #10068

@jeremy-code

Description

@jeremy-code

Provide a general summary of the feature here

Currently, DateFormatter.format in @internationalized/date only supports Date as an input:

/**
* Formats a date as a string according to the locale and format options passed to the
* constructor.
*/
format(value: Date): string {
return this.formatter.format(value);
}

In TypeScript lib ESNext, Intl.DateTimeFormat.format supports the Temporal classes: https://github.com/microsoft/TypeScript/blob/f350b52331494b68c90ab02e2b6d0828d2a22a74/src/lib/esnext.intl.d.ts#L4-L11

🤔 Expected Behavior?

I think it would be nice to support Temporal. When I tried, DateFormatter still worked as expected when typecast as unknown as Date.

😯 Current Behavior

Currently, it throws a type error due to Date and Temporal being different classes.

💁 Possible Solution

Something like this:

type Formattable = Parameters<Intl.DateTimeFormat["format"]>[0]

Would allow different formatted dates based on the current overloads (although it does allow number, which may not be intended)

🔦 Context

I am using Temporal along @internationalized/date. ZonedDateTime in Temporal can be used with arbitrary UTC offsets instead of only those represented in IANA time zone; my app uses Exif data based on timezone offsets and doesn't have access to the timezone.

💻 Examples

No response

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions