Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/johnnyshields/evolve-date-to-ti…
Browse files Browse the repository at this point in the history
…me-local' into evolve-rework
  • Loading branch information
johnnyshields committed Sep 18, 2022
2 parents 0c22046 + c9b1fd8 commit a9277b7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/mongoid/criteria/queryable/extensions/date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __evolve_date__
#
# @return [ Time ] The date as a local time.
def __evolve_time__
::Time.local(year, month, day)
::Time.configured.local(year, month, day).to_time
end

module ClassMethods
Expand Down
54 changes: 44 additions & 10 deletions spec/mongoid/criteria/queryable/extensions/date_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,54 @@

describe "#__evolve_time__" do

let(:date) do
Date.new(2010, 1, 1)
end
context "when using ActiveSupport's time zone" do
include_context 'using AS time zone'

let(:evolved) do
date.__evolve_time__
end
let(:date) do
Date.new(2010, 1, 1)
end

let(:expected) do
Time.local(2010, 1, 1, 0, 0, 0)
let(:expected_time) do
Time.zone.local(2010, 1, 1, 0, 0, 0, 0)
end

let(:evolved) do
date.__evolve_time__
end

it 'is an AS::TimeWithZone' do
expect(evolved.class).to eq(Time)
end

it 'is equal to expected time' do
expect(expected_time).to be_a(ActiveSupport::TimeWithZone)
expect(evolved).to eq(expected_time)
end
end

it "returns the time" do
expect(evolved).to eq(expected)
context "when not using ActiveSupport's time zone" do
include_context 'not using AS time zone'

let(:date) do
Date.new(2010, 1, 1)
end

let(:expected_time) do
Time.local(2010, 1, 1, 0, 0, 0, 0)
end

let(:evolved) do
date.__evolve_time__
end

it 'is a Time' do
expect(evolved.class).to eq(Time)
end

it 'is equal to expected time' do
expect(expected_time).to be_a(Time)
expect(evolved).to eq(expected_time)
end
end
end

Expand Down

0 comments on commit a9277b7

Please sign in to comment.