-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
Expected Behavior
ZonedDateTime and OffsetDateTime should be supported as JobParameters types, similar to LocalDateTime, LocalDate, and LocalTime.
Example usage:
ZonedDateTime scheduleTime = ZonedDateTime.of(2023, 12, 25, 10, 30, 0, 0, ZoneId.of("Asia/Seoul"));
JobParameters parameters = new JobParametersBuilder()
.addJobParameter("schedule.time", scheduleTime, ZonedDateTime.class, true)
.toJobParameters();Current Behavior
Spring Batch currently only provides converters for LocalDateTime, LocalDate, and LocalTime.
ZonedDateTime and OffsetDateTime cannot be used as JobParameters because there are no converters available.
Context
How has this issue affected you?
When working with global services or multi-timezone applications, we need to pass timezone-aware date/time values as JobParameters, but currently only timezone-naive types (LocalDateTime, LocalDate, LocalTime) are supported.
What are you trying to accomplish?
- Execute batch jobs based on specific timezones in global services
- Require both UTC and local timezone in log analysis
- Include timezone information for each country in multi-country services
What other alternatives have you considered?
- Converting to
LocalDateTimeand storing timezone separately (loses timezone information) - Using
Stringtype and parsing manually (error-prone, not type-safe) - Using
Datewith timezone offset (legacy API, not recommended)
Are you aware of any workarounds?
Currently, there is no clean workaround. Users must convert to LocalDateTime and lose timezone information, or use String type which is not type-safe.
Proposed Implementation:
- Add
ZonedDateTimeToStringConverterandStringToZonedDateTimeConverter - Add
OffsetDateTimeToStringConverterandStringToOffsetDateTimeConverter - Register new converters in
DefaultJobParametersConverter - Add related test code