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

Setting the timezone in the init method #199

Open
Tiim opened this issue Sep 29, 2022 · 0 comments
Open

Setting the timezone in the init method #199

Tiim opened this issue Sep 29, 2022 · 0 comments

Comments

@Tiim
Copy link

Tiim commented Sep 29, 2022

Is your feature request related to a problem? Please describe.
I'm using SvelteKit with SSR rendering turned on and the server has a different time zone than the users. This causes formatted times to flicker with the wrong time when loading the page unless the time zone is manually specified as mentioned in issue #148.

Describe the solution you'd like
I would like to be able to set the time zone in the init method. This would still be overridden when specified in the $time method.

// this function can be called on the client side without arguments
// and on the server side with 
// - the locale from the accept-language http header 
// - the time zone from a client side set cookie
export async function initLocalisation(locale, timeZone) {
	register('en', () => import('../locales/en.json'));
	register('de', () => import('../locales/de.json'));

	if (!locale) {
		locale = getLocaleFromNavigator();
	}

	await init({
		fallbackLocale: 'en',
		initialLocale: locale,
		timeZone,
	});
}

Describe alternatives you've considered
Currently all calls to $time and $date must pass the {timeZone: ...} option.

How important is this feature to you?
I think this would be a nice convenience feature, especially since SvelteKit and SSR rendering is getting more popular.

Additional context

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

1 participant