Skip to content

Commit

Permalink
Use vanilla Intl.ResolvedDateTimeFormatOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
alecmev committed Aug 29, 2024
1 parent b715f1a commit de41e1f
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions packages/@internationalized/date/src/DateFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@

let formatterCache = new Map<string, Intl.DateTimeFormat>();

interface ResolvedDateTimeFormatOptions extends Intl.ResolvedDateTimeFormatOptions {
hourCycle?: NonNullable<Intl.DateTimeFormatOptions['hourCycle']>
}

interface DateRangeFormatPart extends Intl.DateTimeFormatPart {
source: 'startRange' | 'endRange' | 'shared'
}
Expand Down Expand Up @@ -79,8 +75,8 @@ export class DateFormatter implements Intl.DateTimeFormat {
}

/** Returns the resolved formatting options based on the values passed to the constructor. */
resolvedOptions(): ResolvedDateTimeFormatOptions {
let resolvedOptions = this.formatter.resolvedOptions() as ResolvedDateTimeFormatOptions;
resolvedOptions(): Intl.ResolvedDateTimeFormatOptions {
let resolvedOptions = this.formatter.resolvedOptions();
if (hasBuggyResolvedHourCycle()) {
if (!this.resolvedHourCycle) {
this.resolvedHourCycle = getResolvedHourCycle(resolvedOptions.locale, this.options);
Expand Down Expand Up @@ -156,10 +152,10 @@ function hasBuggyHour12Behavior() {
let _hasBuggyResolvedHourCycle: boolean | null = null;
function hasBuggyResolvedHourCycle() {
if (_hasBuggyResolvedHourCycle == null) {
_hasBuggyResolvedHourCycle = (new Intl.DateTimeFormat('fr', {
_hasBuggyResolvedHourCycle = new Intl.DateTimeFormat('fr', {
hour: 'numeric',
hour12: false
}).resolvedOptions() as ResolvedDateTimeFormatOptions).hourCycle === 'h12';
}).resolvedOptions().hourCycle === 'h12';
}

return _hasBuggyResolvedHourCycle;
Expand Down

0 comments on commit de41e1f

Please sign in to comment.