Merge branch 'patch-1' of https://github.com/mr-c/arvados into mr-c-patch-1
[arvados.git] / services / api / config / initializers / time_zone.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 ActiveRecord::Base.connection.class.set_callback :checkout, :after do
6   # If the database connection is in a time zone other than UTC,
7   # "timestamp" values don't behave as desired.
8   #
9   # For example, ['select now() > ?', Time.now] returns true in time
10   # zones +0100 and UTC (which makes sense since Time.now is evaluated
11   # before now()), but false in time zone -0100 (now() returns an
12   # earlier clock time, and its time zone is dropped when comparing to
13   # a "timestamp without time zone").
14   raw_connection.sync_exec("SET TIME ZONE 'UTC'")
15 end