Skip to content

Add ZonedDateTime and OffsetDateTime support to JobParametersConverter #5178

@thswlsqls

Description

@thswlsqls

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 LocalDateTime and storing timezone separately (loses timezone information)
  • Using String type and parsing manually (error-prone, not type-safe)
  • Using Date with 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 ZonedDateTimeToStringConverter and StringToZonedDateTimeConverter
  • Add OffsetDateTimeToStringConverter and StringToOffsetDateTimeConverter
  • Register new converters in DefaultJobParametersConverter
  • Add related test code

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions