question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TimezonePicker is too opinionated about "noisy" timezones

See original GitHub issue

Current Behavior

I am situated in timezone “America/Guayaquil”. After scrambling over my timezone not being default selected and reading the TimezonePicker code, it looks like it’s filtering “noisy” timezones (and mine seems to be such). But that has the unwanted side effect of removing the option that could match with Intl.DateTimeFormat().resolvedOptions().timeZone; which makes it either complicated or impossible to have the current user timezone default selected in the dropdown.

Expected Behavior

Filtering should consider the current user timezone and not filter that timezone to allow a default selection. In addition, it should either be possible to disable the filtering completely with a prop to get a complete unfiltered list.

Your Environment

Tech Version
Base UI v8.0.2
React 16.8.6
browser Chrome 75.x
  • I have searched the issues of this repository and believe that this is not a duplicate.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
houmarkcommented, Jul 8, 2019

Thanks again @jh3y!

Overriding in Baseweb is something I still am not too comfortable with, but it is really powerful. There really should be more examples of overrides like this in the docs site to get people started on tweaking and give inspiration to similar overrides.

Here’s my final solution, which dynamically uses the current user time zone, but only if not already existing in the default ones. The added option is sorted into the existing list which makes it possible to make it appear as if it was always there.


const currentTime = new Date();
const myTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
let currentTimezoneOffset = currentTime.getTimezoneOffset();

<TimezonePicker
  overrides={{
    Select: {
      component: props => {
        let options = [...props.options]
        if (!props.options.filter(timezone => timezone.id === myTimeZone).length) {
          options = [...options, {
            id: myTimeZone,
            label: myTimeZone.replace(/ /g, ' ') + ' (GMT ' + formatZonedTime({ zone: { offset: currentTimezoneOffset } }, 'Z') + ': your current time zone)',
            offset: currentTimezoneOffset
          }].sort((a, b) => b.offset - a.offset)
        }
        return (
          <Select
            {...props}
            options={options}
          />
        )
      },
    }
  }}
/>

Hope it helps someone out!

1reaction
houmarkcommented, Jul 8, 2019

Hey @jh3y!

Thanks for your feedback. I considered that option, but never got to try it. But if you are in fact in a time zone that’s already in the list, won’t I have duplicates? How can I know? I guess I can look at the list of countries before in some way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I get notified when the timezone-picker value is ...
I'm using timezone-picker to pick my timezones, and so far it's working great. However, the one problem is that I can't convince it...
Read more >
It's Time We Addressed Time-Zone Selectors
Designing time-zone selectors can be tricky because: Time zones can change. A time zone can change its offset if it abides by daylight...
Read more >
Time zone picker in System Settings does not show time ...
The below KB describes one of the reason why the time zone picker shows empty. In the console error we can see 400...
Read more >
Case study: The UX of selecting timezones - Bootcamp
The first is very obvious: It is hard for a user to choose the correct value if they are not familiar with the...
Read more >
Timezone Picker - Symphony Developers Documentation
With the Timezone Picker, Symphony users can easily select a timezone from a selection of possible values. It recognises both cities and countries...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found