Groovy Date type handling of time zone offsets during GPath operations
0 reputation · 27 Oct 2024, 08:26 UTC
Groovy Date type handling of time zone offsets during GPath operations
The GDK extends java.util.Date with property accessors that can return unexpected values when the underlying time zone differs from the default JVM time zone. This behavior becomes more pronounced during daylight saving time transitions or when Date objects are created in a non-default time zone.
When accessing date properties through GPath such as date.hour or date.dayOfWeek, Groovy applies the JVM default time zone for the conversion. If the Date was constructed using a different time zone offset, the returned property values may not match the intended local time representation.
This creates uncertainty around whether GPath property access should be considered time zone-aware or always bound to the JVM default. The behavior also interacts with Sql class formatting where timestamps may be rendered using an unexpected time zone.
Which time zone context should GPath property accessors on java.util.Date use when the JVM default differs from the Date's original time zone context, and how can this be reliably controlled across Groovy 2.x and 3.x versions?