Using Samay
This section explains how to use the main features of the Samay library in your Spring Boot application.
Installing Samay
Timezone Extraction
By default, Samay expects the timezone in a request header named X-TimeZone
.
To extract and store timezone on each request:
No need to manually extract the timezone. Samay handles it automatically.
Accessing Timezone
To access the extracted timezone in your controllers or services:
The timezone is available via Samay.getTimeZone()
anywhere downstream.
Changing Header Name
To customize the request header name:
Samay will now check My-Timezone-Header
instead of default X-TimeZone
.
Enabling thread inheritance
The default behavior of Samay is to not inherit the timezone information in child threads. You can enable thread inheritance by adding the following property to your application.properties
:
Disable Auto Configuration
To disable the auto configuration in Spring Boot:
And manually configure the interceptor:
ThreadLocal Cleanup
Samay automatically cleans up the thread local after the request is handled. No need for manual removal.