Grails 5.3 Date Binding Time Zone Configuration Change and Its Impact on Persisted Dates
0 reputation · 24 Aug 2021, 15:19 UTC
0 reputation · 24 Aug 2021, 15:19 UTC
Determine a consistent date‑binding strategy for a Grails application that serves users across multiple regions while preserving the intent of user‑entered dates and avoiding unexpected shifts after persistence.
Given these factors, what approach should be taken to balance data integrity, upgrade effort and user experience?
Should grails.databinding.dateTimeZone be set to UTC globally to normalize stored timestamps?
How can original time‑zone information be preserved without framework‑level support?
What migration steps are required when moving from Grails 5.x to Grails 6 where the dateTimeZone property is removed?
Set grails.databinding.dateTimeZone = 'UTC' globally only if your application treats all incoming dates as absolute instants and does not need to reconstruct the user's original local wall-clock time. If the original time zone is required for business logic or auditing, you must capture the zone metadata in a separate database column, as java.util.Date does not store zone information.
grails.databinding.dateTimeZone property normalizes incoming date strings to the specified zone before converting them to a java.util.Date.java.util.Date as a raw epoch value. Any zone metadata from the input string is discarded upon persistence.dateTimeZone property is removed. The framework shifts toward JSR-310 types (java.time.*), which can natively store offsets or zones.Since the framework does not provide a built-in mechanism to retain the input zone for java.util.Date fields, use the following pattern:
String originalTz or Integer offsetMinutes column to your domain class.DateTimeFormatter.ISO_OFFSET_DATE_TIME.originalTz field while passing the normalized UTC instant to the Date field.originalTz to format the date back to the user's local time.Upgrading requires a shift from legacy date types to the Java 8 Date-Time API to avoid data drift after the dateTimeZone property is removed:
java.util.Date with java.time.OffsetDateTime (for absolute points in time with offsets) or java.time.ZonedDateTime (for zone-aware dates).where clauses and criteria queries to use JSR-310 types, as semantics for date ranges may differ from java.util.Date.JavaTimeModule for Jackson to ensure JSON APIs correctly serialize the new types.grails.databinding.dateTimeZone from application.yml.To ensure integrity during migration or configuration changes, perform these checks:
'2026-10-14T10:00:00-04:00' and verify the persisted epoch matches 2026-10-14T14:00:00Z.UTC and one to America/Los_Angeles) and verify that the formatted output for the same record remains consistent.Does your business logic require the exact local wall-clock time as entered by the user, or is a normalized UTC instant sufficient for all consumers? If the former, the separate zone column is mandatory.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.