Skip to content

Commit 2cfa478

Browse files
committed
Fix timezone drift
1 parent 19f97ec commit 2cfa478

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

spec/integration/criteria/raw_value_spec.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,15 @@
468468
end
469469

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

474-
it 'matches objects without raw value when non-exact' do
475-
expect(Band.where(founded: Time.at(1577923199)).to_a).to eq [band3, band4]
474+
it 'matches objects without raw value when 1 second before midnight' do
475+
expect(Band.where(founded: Time.at(1577923199).utc).to_a).to eq [band1, band2]
476+
end
477+
478+
it 'matches objects without raw value when 1 second after midnight' do
479+
expect(Band.where(founded: Time.at(1577923201).utc).to_a).to eq [band3, band4]
476480
end
477481
end
478482

@@ -492,28 +496,28 @@
492496

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

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

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

508512
it 'matches objects without raw value' do
509513
Time.use_zone('UTC') do
510-
expect(Band.where(updated: Time.at(1577923200).to_date).to_a).to eq [band7]
514+
expect(Band.where(updated: Time.at(1577923200).utc.to_date).to_a).to eq [band7]
511515
end
512516
end
513517

514518
it 'does not matches objects without raw value when in other timezone' do
515519
Time.use_zone('Asia/Tokyo') do
516-
expect(Band.where(updated: Time.at(1577923200).to_date).to_a).to eq []
520+
expect(Band.where(updated: Time.at(1577923200).utc.to_date).to_a).to eq []
517521
end
518522
end
519523
end

0 commit comments

Comments
 (0)