File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
lib/dfe/analytics/services Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,25 @@ def supported_adapter_and_environment?
4545 end
4646
4747 def fetch_current_timestamp_in_time_zone
48- Time . use_zone ( TIME_ZONE ) { Time . zone . now . iso8601 ( 6 ) }
48+ utc_timestamp = case connection . adapter_name . downcase
49+ when 'postgresql' , 'postgis'
50+ connection . select_value ( "SELECT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC')::text AS current_timestamp_utc" )
51+ when 'sqlite3' , 'sqlite'
52+ connection . select_value ( "SELECT CURRENT_TIMESTAMP AS current_timestamp_utc" )
53+ else
54+ nil
55+ end
56+
57+ if utc_timestamp . present?
58+ Time . use_zone ( TIME_ZONE ) do
59+ utc_time = Time . find_zone ( 'UTC' ) . parse ( utc_timestamp )
60+ utc_time . in_time_zone ( Time . zone ) . iso8601 ( 6 )
61+ end
62+ else
63+ # Fallback: use application clock but make the choice explicit
64+ Rails . logger . warn ( "fetch_current_timestamp_in_time_zone: unknown DB adapter '#{ connection . adapter_name } ', falling back to app clock" )
65+ Time . use_zone ( TIME_ZONE ) { Time . zone . now . iso8601 ( 6 ) }
66+ end
4967 end
5068
5169 def id_column_exists_for_entity? ( entity_name )
You can’t perform that action at this time.
0 commit comments