Skip to content

#4027 Fix mapping ZonedDateTime or OffsetDateTime to LocalDateTime#4047

Merged
hduelme merged 6 commits into
mapstruct:mainfrom
Takch02:feature/4027-zoned-to-local-datetime
May 24, 2026
Merged

#4027 Fix mapping ZonedDateTime or OffsetDateTime to LocalDateTime#4047
hduelme merged 6 commits into
mapstruct:mainfrom
Takch02:feature/4027-zoned-to-local-datetime

Conversation

@Takch02

@Takch02 Takch02 commented May 3, 2026

Copy link
Copy Markdown
Contributor

Fixes #4027

Added implicit conversion support for:

  • ZonedDateTime → LocalDateTime (via toLocalDateTime())
  • OffsetDateTime → LocalDateTime (via toLocalDateTime())
  • LocalDateTime → ZonedDateTime (via atZone(ZoneOffset.UTC))
  • LocalDateTime → OffsetDateTime (via atOffset(ZoneOffset.UTC))
  • ZonedDateTime → Instant (via toInstant())
  • OffsetDateTime → Instant (via toInstant())
  • Instant → ZonedDateTime (via atZone(ZoneOffset.UTC))
  • Instant → OffsetDateTime (via atOffset(ZoneOffset.UTC))

Changes:

  • Added JavaZonedDateTimeToLocalDateTimeConversion
  • Added JavaOffsetDateTimeToLocalDateTimeConversion
  • Added JavaOffsetDateTimeToInstantConversion
  • Added JavaZoneDateTimeToInstantConversion.java
  • Added offsetDateTime() helper in ConversionUtils
  • Added register() calls in Conversions.java
  • Added ZonedOffsetDateTimeToLocalDateTimeConversionTest
  • Added fixture for SourceTargetMapperImpl

@Takch02

Takch02 commented May 3, 2026

Copy link
Copy Markdown
Contributor Author

@filiphr @JanecekPetr Please Review! Thank you.

@hduelme

hduelme commented May 22, 2026

Copy link
Copy Markdown
Contributor

@Takch02 nice implementation.
I see why you assumed that getFromExpression should not be implemented. However, in other conversions we already use ZoneOffset.UTC as a default value, for example in JavaLocalDateToDateConversion and JavaLocalDateToSqlDateConversion.
Could you add the getFromExpression implementation and the according tests?

@Takch02

Takch02 commented May 23, 2026

Copy link
Copy Markdown
Contributor Author

@Takch02 nice implementation. I see why you assumed that getFromExpression should not be implemented. However, in other conversions we already use ZoneOffset.UTC as a default value, for example in JavaLocalDateToDateConversion and JavaLocalDateToSqlDateConversion. Could you add the getFromExpression implementation and the according tests?

@hduelme Thanks for the review! I added getFromExpression and related tests.

@hduelme

hduelme commented May 23, 2026

Copy link
Copy Markdown
Contributor

@Takch02 the implementation looks clean to me.
Could you add the missing license header to SourceTargetMapperImpl? We ignore license headers in diffs, but we still want every file to include one.

Additionally, @JanecekPetr noticed that mapping to/from Instant is still missing:

Similarly, I now see that neither ZonedDateTime nor OffsetDateTime cannot be converted to Instant at all, even though zonedDateTime.toInstant() exists.

If you'd like, you could implement those mappings as well.

@Takch02

Takch02 commented May 23, 2026

Copy link
Copy Markdown
Contributor Author

@Takch02 the implementation looks clean to me. Could you add the missing license header to SourceTargetMapperImpl? We ignore license headers in diffs, but we still want every file to include one.

Additionally, @JanecekPetr noticed that mapping to/from Instant is still missing:

Similarly, I now see that neither ZonedDateTime nor OffsetDateTime cannot be converted to Instant at all, even though zonedDateTime.toInstant() exists.

If you'd like, you could implement those mappings as well.

@hduelme Thank you! l added license headers and conversion Instant/LocalDataTime, Instant/ZoneDateTime

@hduelme

hduelme commented May 23, 2026

Copy link
Copy Markdown
Contributor

@Takch02 thanks a lot.
I forgot to mention earlier that built-in conversions are documented in chapter-5-data-type-conversions.asciidoc. Could you also add documentation for the 4 newly added conversions?

@Takch02

Takch02 commented May 24, 2026

Copy link
Copy Markdown
Contributor Author

@Takch02 thanks a lot. I forgot to mention earlier that built-in conversions are documented in chapter-5-data-type-conversions.asciidoc. Could you also add documentation for the 4 newly added conversions?

@hduelme Thank you! I added documentation for the 4 new conversion.

@hduelme hduelme merged commit 428fd27 into mapstruct:main May 24, 2026
9 checks passed
@hduelme

hduelme commented May 24, 2026

Copy link
Copy Markdown
Contributor

@Takch02 thanks again. Its now merged.

@Takch02

Takch02 commented May 24, 2026

Copy link
Copy Markdown
Contributor Author

@hduelme Thank you!!

@Takch02 Takch02 deleted the feature/4027-zoned-to-local-datetime branch May 25, 2026 04:28
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

Successfully merging this pull request may close these issues.

Mapping ZonedDateTime or OffsetDateTime to LocalDateTime

2 participants