Skip to content

Commit

Permalink
Use tooltip for the Timezone only when necessary.
Browse files Browse the repository at this point in the history
  • Loading branch information
afercia committed Nov 21, 2023
1 parent e95bb8c commit b2970df
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/components/src/date-time/time/timezone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,22 @@ const TimeZone = () => {
? timezone.abbr
: `UTC${ offsetSymbol }${ timezone.offset }`;

// Replace underscore with space in strings like `America/Costa_Rica`.
const prettyTimezoneString = timezone.string.replace( '_', ' ' );

const timezoneDetail =
'UTC' === timezone.string
? __( 'Coordinated Universal Time' )
: `(${ zoneAbbr }) ${ timezone.string.replace( '_', ' ' ) }`;
: `(${ zoneAbbr }) ${ prettyTimezoneString }`;

const isAbbrSameAsDetails =
`${ zoneAbbr } ${ prettyTimezoneString }`.trim() === zoneAbbr;

return (
return isAbbrSameAsDetails ? (
<StyledComponent className="components-datetime__timezone">
{ zoneAbbr }
</StyledComponent>
) : (
<Tooltip placement="top" text={ timezoneDetail }>
<StyledComponent className="components-datetime__timezone">
{ zoneAbbr }
Expand Down

0 comments on commit b2970df

Please sign in to comment.