Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Control Added to Include Timezones that has issue with altname and ab… #96

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ const TimezoneSelect = ({
const tzStrings = soft(zone[0])

let label = ''
let abbr = now.isDST()
? tzStrings[0].daylight.abbr
: tzStrings[0].standard.abbr
let altName = now.isDST()
? tzStrings[0].daylight.name
: tzStrings[0].standard.name

const standardAbbr = tzStrings?.[0]?.standard?.abbr ?? ''
const dstAbbr = tzStrings?.[0]?.daylight?.abbr ?? standardAbbr

let abbr = now.isDST() ? dstAbbr : standardAbbr

const standardAltName = tzStrings?.[0]?.standard?.name ?? ''
const dstAltName = tzStrings?.[0]?.daylight?.name ?? standardAltName

let altName = now.isDST() ? dstAltName : standardAltName

const min = tz.current.offset * 60
const hr =
Expand All @@ -47,7 +51,7 @@ const TimezoneSelect = ({
label = prefix
break
case 'altName':
label = `${prefix} ${altName?.length ? `(${altName})` : ''}`
label = `${prefix} ${altName ? `(${altName})` : ''}`
break
case 'abbrev':
label = `${prefix} (${abbr.substring(0, maxAbbrLength)})`
Expand Down
15 changes: 15 additions & 0 deletions src/tests/TimezoneSelect.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,18 @@ test('load and show abbrevations according to default maxAbbrLength(4)', async (
)
expect(getByText(/Chihuahua/)).not.toContain('H(N|E)PMX')
})

test('load and does not omit timezone that isDST is true and doesn not have daylight definitions', async () => {
const { getByText } = render(
<TimezoneSelect
value={'Asia/Tehran'}
timezones={{
...allTimezones,
'Asia/Tehran': 'Tehran',
}}
onChange={e => e}
/>
)

expect(getByText(/Tehran/)).toBeInTheDocument()
})