Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Changing timezone do not produce effect #855

Closed
wysman opened this issue Apr 23, 2020 · 1 comment · Fixed by #859
Closed

Changing timezone do not produce effect #855

wysman opened this issue Apr 23, 2020 · 1 comment · Fixed by #859
Labels
help wanted Extra attention is needed Status: PR Welcome Welcome to Pull Request Type: Bug Bug or Bug fixes

Comments

@wysman
Copy link

wysman commented Apr 23, 2020

Hi,

I use the setDateTimeFormat function to update the dateTimeFormats definitions to allow users to select their preferred timezone or change the timezone based on their current activity. The following code is an simplified extract of our code to flip/flop timezone between Europe/Paris to UTC.

  const locales = i18n.availableLocales;
  locales.forEach((locale) => {
    let formats = i18n.getDateTimeFormat(locale)
    Object.keys(formats).forEach((index) => {
      if (formats[index].timeZone === 'UTC') {
        formats[index].timeZone = 'Europe/Paris'
      } else {
        formats[index].timeZone = 'UTC'
      }
    });
    i18n.setDateTimeFormat(locale, formats);
  });

This code allows to change the dateTimeFormat configuration but do not have any effect on date rendering. By adding the following tricks, the timeZone is correctly used during rendering.

  // Clear some cache ???
  i18n._dateTimeFormatters = {}

I think vue-i18n must clear clean its internal cache when the configuration change.
Also, it's can be nice to have an overall timezone setting too.

Best regards,

@kazupon kazupon added help wanted Extra attention is needed Status: PR Welcome Welcome to Pull Request Type: Bug Bug or Bug fixes labels Apr 25, 2020
kazupon added a commit that referenced this issue Apr 25, 2020
kazupon added a commit that referenced this issue Apr 25, 2020
@wysman
Copy link
Author

wysman commented Apr 28, 2020

@kazupon Thanks for the quick fix !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed Status: PR Welcome Welcome to Pull Request Type: Bug Bug or Bug fixes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants