Data Source Time Zone vs. SQL-Level Conversion for Consistent Timestamps
0 reputation · 06 Apr 2023, 16:16 UTC
0 reputation · 06 Apr 2023, 16:16 UTC
WebStorm's integrated database tools allow for the configuration of a specific time zone per data source. When configured, the JDBC driver converts TIMESTAMP or datetime values between the server's zone and the specified IDE zone before rendering them in the data editor.
There is a design tension between ensuring team-wide consistency and maintaining local readability:
A critical uncertainty arises when combining IDE-level conversion with application-level SQL functions such as AT TIME ZONE or CONVERT_TZ. Performing both operations may result in double-conversion of the timestamp.
Should time zone normalization be handled exclusively via the WebStorm data source settings to maintain a clean SQL layer, or is it safer to perform conversions within the SQL query to ensure the result set is immutable regardless of IDE configuration? How can a team verify that the JDBC driver is not applying an implicit offset that conflicts with explicit SQL conversion functions?
32775 reputation · 06 Apr 2023, 17:15 UTC
Put canonical normalization in the SQL layer and set the WebStorm data source to UTC. Doing both is not redundant — it is the combination that makes the result set immutable: the query controls what the database returns, and the UTC data source setting neutralizes the JDBC driver's display-side conversion so what you see matches the wire value.
The genuinely dangerous configuration is the opposite: an IDE-level offset (or an unset driver default) stacked on top of AT TIME ZONE / CONVERT_TZ in the query. That produces double-conversion, and it is silent — the numbers look plausible, just shifted.
WebStorm's per-data-source time zone setting does not transform data itself; it configures the JDBC driver, which converts TIMESTAMP WITHOUT TIME ZONE values between the server session zone and the configured zone during retrieval. Two consequences follow:
psql, DBeaver, or a CI script sees different values unless every client repeats the same configuration.TIMESTAMP WITHOUT TIME ZONE zone handling implementation-defined, so behavior varies across drivers (PostgreSQL, MySQL Connector/J, SQL Server) and across driver versions.An explicit conversion in the query — for example SELECT created_at AT TIME ZONE 'UTC' FROM ... — travels with the SQL, not with anyone's IDE. That is what makes the result set portable.
Driver-level conversion applies to zone-less types (TIMESTAMP WITHOUT TIME ZONE, MySQL datetime). Zone-aware types such as PostgreSQL timestamptz carry offset metadata and are typically returned as-is, so they are largely immune. If your schema stores timestamptz normalized to UTC at write time, the cleanest setup is:
timestamptz) in the database.This also sidesteps a known trap: some drivers (notably MySQL Connector/J 8.0+) fall back to the JVM's default zone unless connectionTimeZone or forceConnectionTimeZoneToSession is set, so "no configuration" is itself a hidden, machine-dependent offset.
SHOW TIME ZONE; (PostgreSQL) or SELECT @@session.time_zone; (MySQL).connectionTimeZone, serverTimezone, or forceConnectionTimeZoneToSession, plus the data source's own time zone field.SELECT TIMESTAMP '2024-01-15 12:00:00' AS ts;, and compare the IDE-rendered value against a known-UTC client (psql or mysql with TZ=UTC). Any difference is your implicit offset.FINEST) to inspect the literal timestamp strings on the wire..idea/dataSources.xml, a UTC change affects the whole team — coordinate or document it.hibernate.jdbc.time_zone), independent of the IDE; verify application behavior separately.ALTER DATABASE ... SET timezone shifts the baseline for driver conversion with no code or IDE change.One missing detail would sharpen this recommendation: which database and driver you use, since the exact property names and defaults differ. The architecture advice above holds regardless.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.