Fixes #2085 - timezone issue with elasticsearch

This commit is contained in:
Mantas Masalskis 2021-07-06 18:40:09 +00:00 committed by Thorsten Eckel
parent d0d00bf62c
commit a99f87abe6
3 changed files with 20 additions and 0 deletions

View file

@ -285,6 +285,7 @@ remove whole data from index
condition = { condition = {
'query_string' => { 'query_string' => {
'query' => append_wildcard_to_simple_query(query), 'query' => append_wildcard_to_simple_query(query),
'time_zone' => Setting.get('timezone_default').presence || 'UTC',
'default_operator' => 'AND', 'default_operator' => 'AND',
'analyze_wildcard' => true, 'analyze_wildcard' => true,
} }

View file

@ -69,6 +69,22 @@ RSpec.describe SearchIndexBackend, searchindex: true do
it { is_expected.to be_an(Array).and not_include(nil).and be_empty } it { is_expected.to be_an(Array).and not_include(nil).and be_empty }
end end
end end
context 'search with date that requires time zone conversion', time_zone: 'Europe/Vilnius' do
let(:record_type) { 'Ticket'.freeze }
let(:record) { create :ticket }
before do
travel_to(Time.zone.parse('2019-01-01 23:33'))
described_class.add(record_type, record)
described_class.refresh
end
it 'finds record in effective time zone' do
result = described_class.search('created_at: [2019-01-01 TO 2019-01-01]', record_type)
expect(result).to eq([{ id: record.id.to_s, type: record_type }])
end
end
end end
describe '.append_wildcard_to_simple_query' do describe '.append_wildcard_to_simple_query' do

View file

@ -3,11 +3,14 @@
RSpec.configure do |config| RSpec.configure do |config|
config.around(:each, :time_zone) do |example| config.around(:each, :time_zone) do |example|
if example.metadata[:type] == :system if example.metadata[:type] == :system
# RSpec System/Capybara tests use TZ variable to set timezone in browser
old_tz = ENV['TZ'] old_tz = ENV['TZ']
ENV['TZ'] = example.metadata[:time_zone] ENV['TZ'] = example.metadata[:time_zone]
example.run example.run
else else
# Other RSpec tests run inside of the same process and don't take TZ into account.
# Mocking time zone via Time object is enough
Time.use_zone(example.metadata[:time_zone]) { example.run } Time.use_zone(example.metadata[:time_zone]) { example.run }
end end
ensure ensure