Skip to content

Commit

Permalink
Normalize date formatting whitespace issues
Browse files Browse the repository at this point in the history
The new Intl.dateFormat functions sometimes use a
"Narrow No-Break Space" instead of a normal space
in the dates, before the AM/PM suffices.

The behavior seems to be somewhat non-deterministic, which
makes testing difficult.

This change simply normalizes the output to always use a simple space.
  • Loading branch information
csillag authored and lukaw3d committed Mar 3, 2023
1 parent 8287947 commit 132ba81
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/app/components/DateFormatter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@ const dateFormat = new Intl.DateTimeFormat(process?.env?.NODE_ENV === 'test' ? '
timeZone: process?.env?.NODE_ENV === 'test' ? 'UTC' : undefined,
})

export const intlDateTimeFormat = (date: Date | number) => dateFormat.format(date)
/**
* Narrow No-Brake Space
*
* This is used by the date formatter.
* See https://unicodeplus.com/U+202F
*/
const NNBSP = '\u202F'

export const intlDateTimeFormat = (date: Date | number) => dateFormat.format(date).replaceAll(NNBSP, ' ')

export function DateFormatter(props: Props) {
return <>{intlDateTimeFormat(props.date)}</>
return <>{intlDateTimeFormat(props.date).replaceAll(NNBSP, ' ')}</>
}

0 comments on commit 132ba81

Please sign in to comment.