Skip to content

Commit

Permalink
Fix timezone drift
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyshields committed Sep 18, 2022
1 parent 19f97ec commit 2cfa478
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions spec/integration/criteria/raw_value_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,15 @@
end

it 'matches objects without raw value when exact' do
expect(Band.where(founded: Time.at(1577923200)).to_a).to eq [band3, band4]
expect(Band.where(founded: Time.at(1577923200).utc).to_a).to eq [band3, band4]
end

it 'matches objects without raw value when non-exact' do
expect(Band.where(founded: Time.at(1577923199)).to_a).to eq [band3, band4]
it 'matches objects without raw value when 1 second before midnight' do
expect(Band.where(founded: Time.at(1577923199).utc).to_a).to eq [band1, band2]
end

it 'matches objects without raw value when 1 second after midnight' do
expect(Band.where(founded: Time.at(1577923201).utc).to_a).to eq [band3, band4]
end
end

Expand All @@ -492,28 +496,28 @@

context 'Date field' do
it 'matches objects with raw value' do
expect(Band.where(founded: Mongoid::RawValue(Time.at(1577923200).to_date)).to_a).to eq [band3, band4]
expect(Band.where(founded: Mongoid::RawValue(Time.at(1577923200).utc.to_date)).to_a).to eq [band3, band4]
end

it 'matches objects without raw value when non-exact' do
expect(Band.where(founded: Time.at(1577923200).to_date).to_a).to eq [band3, band4]
expect(Band.where(founded: Time.at(1577923200).utc.to_date).to_a).to eq [band3, band4]
end
end

context 'Time field' do
it 'matches objects with raw value' do
expect(Band.where(updated: Mongoid::RawValue(Time.at(1577923200).to_date)).to_a).to eq [band7]
expect(Band.where(updated: Mongoid::RawValue(Time.at(1577923200).utc.to_date)).to_a).to eq [band7]
end

it 'matches objects without raw value' do
Time.use_zone('UTC') do
expect(Band.where(updated: Time.at(1577923200).to_date).to_a).to eq [band7]
expect(Band.where(updated: Time.at(1577923200).utc.to_date).to_a).to eq [band7]
end
end

it 'does not matches objects without raw value when in other timezone' do
Time.use_zone('Asia/Tokyo') do
expect(Band.where(updated: Time.at(1577923200).to_date).to_a).to eq []
expect(Band.where(updated: Time.at(1577923200).utc.to_date).to_a).to eq []
end
end
end
Expand Down

0 comments on commit 2cfa478

Please sign in to comment.