LocaleContextResolver and time zone
We need to have information about the client's time zone so that we can correctly respond to API requests. LocaleContextResolver
adds support for a rich locale context (potentially including locale and time zone information). We already use it to determine the language (see BaseTranslationSupport
) in SpringMvcConfig
:
@Bean
public LocaleResolver localeResolver() {
AcceptHeaderLocaleResolver localeResolver = new AcceptHeaderLocaleResolver();
localeResolver.setDefaultLocale(Locale.forLanguageTag(defaultLocale));
// We could look at localeResolver.setSupportedLocales()...
return localeResolver;
}
We should extend this with detecting the timezone from the request headers. Date is listed in the forbidden header names in the fetch spec, so this code will not send the Date header according to 1.
I think our best option is to look for a custom X-Timezone
HTTP request header that needs to contain a readable TimeZone
. API clients can set and send this request header with each API request. Alternatively we can maybe use something from Locale
or the Cooperator
as a default.
Most incoming timestamps already include time zone offsets, so we are able to properly read incoming dates (e.g. 2022-08-03
) and use them when querying the database for timestamps in UTC
.
I'm still trying to find a good API endpoint to test this. Suggestions are welcome.