Skip to content

Commit

Permalink
Times can now evolve to dates. Closes mongoid#31
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Apr 3, 2012
1 parent d7b5301 commit 437cf7c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/origin/extensions/time.rb
Expand Up @@ -5,6 +5,18 @@ module Extensions
# This module contains additional time behaviour.
module Time

# Evolve the time as a date, UTC midnight.
#
# @example Evolve the time to a date query format.
# time.__evolve_date__
#
# @return [ Time ] The date at midnight UTC.
#
# @since 1.0.0
def __evolve_date__
::Time.utc(year, month, day, 0, 0, 0, 0)
end

# Evolve the time into a utc time.
#
# @example Evolve the time.
Expand Down
15 changes: 15 additions & 0 deletions spec/origin/extensions/time_spec.rb
Expand Up @@ -318,6 +318,21 @@
end
end

describe "#__evolve_date__" do

let(:time) do
Time.new(2010, 1, 1, 12, 0, 0)
end

let(:evolved) do
time.__evolve_date__
end

it "returns midnight utc" do
evolved.should eq(Time.utc(2010, 1, 1, 0, 0, 0))
end
end

describe "#__evolve_time__" do

let(:time) do
Expand Down

0 comments on commit 437cf7c

Please sign in to comment.