Skip to content

fix(@formatjs/intl-datetimeformat): fix formatRange h24 midnight and hour12 duplication#6026

Merged
longlho merged 1 commit intomainfrom
claude/issue-4535-20260214-0528
Feb 14, 2026
Merged

fix(@formatjs/intl-datetimeformat): fix formatRange h24 midnight and hour12 duplication#6026
longlho merged 1 commit intomainfrom
claude/issue-4535-20260214-0528

Conversation

@longlho
Copy link
Member

@longlho longlho commented Feb 14, 2026

Fixes #4535

Summary

This PR fixes two bugs in FormattedDateTimeRange that were causing incorrect formatting:

  1. H24 midnight rendering: Same-day ranges starting at midnight showing "24:00" instead of "00:00"
  2. Date duplication with hour12: Date/day duplicated for any time range when hour12: true

Changes

Bug 1: H24 Midnight Rendering

Root Cause: The condition !rangeFormatOptions?.isDifferentDate meant "convert 0→24 when NOT in a range with different dates". Same-day ranges have isDifferentDate: false, causing unwanted conversion.

Fix in FormatDateTimePattern.ts:

  • Changed from: if (v === 0 && !rangeFormatOptions?.isDifferentDate)
  • Changed to: if (v === 0 && !rangeFormatOptions)
  • Now 0→24 conversion only happens in non-range single-date formatting

Example:

  • Before: Sun, 3 May 2026, 24:00–24:45
  • After: Sun, 3 May 2026, 00:00–00:45

Bug 2: Hour12 Date Duplication

Root Cause: CLDR data synthesis fallback to alternate hour cycles (12hr ↔ 24hr) only checked if timeIntervalFormats was undefined or not an object, missing the case where it's an empty object {}.

Fix in extract-dates.ts:

  • Added Object.keys(timeIntervalFormats).length === 0 check
  • Now properly triggers fallback when interval formats are empty
  • Ensures 12-hour skeletons can use 24-hour interval patterns during data generation

Example:

  • Before: Wed, 18 Feb 2026, 7:00 am – Wed, 18 Feb 2026, 4:00 pm
  • After: Wed, 18 Feb 2026, 7:00 am – 4:00 pm

Tests

Added 3 comprehensive test cases:

  1. Same-day midnight range (h24 format)
  2. Same-period hour12 range (both PM)
  3. Cross-period hour12 range (AM to PM)

Breaking Changes

None. These are bug fixes that make behavior match user expectations and LDML specifications.

Note: The fix to extract-dates.ts requires regenerating locale data before merging.

Generated with Claude Code

…hour12 duplication

Fixes #4535

This commit addresses two issues with FormattedDateTimeRange:

1. **H24 midnight rendering**: Same-day ranges starting at midnight
   (e.g., 00:00-00:45) were incorrectly showing "24:00-24:45" instead
   of "00:00-00:45".

   Root cause: The condition !rangeFormatOptions?.isDifferentDate meant
   "convert 0→24 when NOT in a range with different dates". Same-day
   ranges have isDifferentDate:false, causing unwanted conversion.

   Fix: Changed to !rangeFormatOptions (undefined check), so 0→24
   conversion only happens in non-range single-date formatting.

2. **Date duplication with hour12**: When hour12:true, date/day were
   duplicated for any time range (e.g., "Wed, 18 Feb 2026, 7:00 am –
   Wed, 18 Feb 2026, 4:00 pm" instead of showing date once).

   Root cause: CLDR data synthesis fallback to alternate hour cycles
   (12hr ↔ 24hr) only checked if timeIntervalFormats was undefined or
   not an object, missing the case where it's an empty object {}.

   Fix: Added Object.keys().length === 0 check to properly trigger
   fallback when interval formats are empty, ensuring 12-hour skeletons
   can use 24-hour interval patterns during data generation.

Co-authored-by: Long Ho <longlho@users.noreply.github.com>
@longlho longlho merged commit 3d03ab1 into main Feb 14, 2026
7 checks passed
@longlho longlho deleted the claude/issue-4535-20260214-0528 branch February 14, 2026 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Weird behavior of FormattedDateTimeRange in React Native

1 participant