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

How to handle different timezones in nodejs #20

Closed
shadizar128 opened this issue Mar 27, 2020 · 6 comments
Closed

How to handle different timezones in nodejs #20

shadizar128 opened this issue Mar 27, 2020 · 6 comments

Comments

@shadizar128
Copy link

shadizar128 commented Mar 27, 2020

Hi, I am trying to use this module in nodejs to send emails to different customers. Each customer can have a different language and/or timezone. Do you have any examples on how to set the timezone per call? All i have now is this

function getText(lang) {
  return i18next.t('This is an example of date formatting: {value, date, short}', {lang: lang, value: new Date()});
}
@jamuhl
Copy link
Member

jamuhl commented Mar 27, 2020

you might have a look at: https://momentjs.com/timezone/

@jamuhl
Copy link
Member

jamuhl commented Mar 27, 2020

And further you might look at formatjs website - as i18next-icu used that

@shadizar128
Copy link
Author

shadizar128 commented Mar 27, 2020

Using momentjs or formatjs would imply I not use this module at all, right?
Or something like:

const dateString = IIntl.DateTimeFormat('fr', options).format(new Date());
i18next.t('This is an example of date formatting: {value}', {value: dateString});

@jamuhl
Copy link
Member

jamuhl commented Mar 27, 2020

using momentjs yes

formatjs -> this module is based on the formatjs implementation

@shadizar128
Copy link
Author

shadizar128 commented Mar 27, 2020

And formatjs uses Intl.DateTimeFormat as I see it but its options are not exposed in i18next-icu. I can only set:

i18next.use(ICU).init({
  i18nFormat: {
    formats: {
      datetime: {
        custom: {
          year: 'numeric',
          month: 'numeric',
          day: 'numeric',
          hour: 'numeric',
          minute: 'numeric',
          second: 'numeric',
          timeZoneName: 'long',
          timezone: 'UTC'
        }
      }
    }
  }
});

However, this is a static config, I cannot change it on a call by call basis.

@jamuhl
Copy link
Member

jamuhl commented Mar 27, 2020

Like said...it replaces the format used by i18next with the one from formatjs -> there is no mix

@jamuhl jamuhl closed this as completed Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants