Permalink
Browse files

use dates to search for dates

  • Loading branch information...
1 parent dd790dd commit 85583c0fac68705127e342bca47515208066c953 @nragaz committed Sep 21, 2011
Showing with 32 additions and 25 deletions.
  1. +16 −15 Gemfile.lock
  2. +16 −10 lib/date_range_scopes.rb
View
31 Gemfile.lock
@@ -37,27 +37,27 @@ GEM
activesupport (= 3.1.0.rc4)
activesupport (3.1.0.rc4)
multi_json (~> 1.0)
- arel (2.1.1)
+ arel (2.1.4)
bcrypt-ruby (2.1.4)
builder (3.0.0)
erubis (2.7.0)
- hike (1.0.0)
+ hike (1.2.1)
i18n (0.6.0)
mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
multi_json (1.0.3)
- polyglot (0.3.1)
- rack (1.3.0)
- rack-cache (1.0.2)
+ polyglot (0.3.2)
+ rack (1.3.3)
+ rack-cache (1.0.3)
rack (>= 0.4)
- rack-mount (0.8.1)
+ rack-mount (0.8.3)
rack (>= 1.0.0)
rack-ssl (1.3.2)
rack
- rack-test (0.6.0)
+ rack-test (0.6.1)
rack (>= 1.0)
rails (3.1.0.rc4)
actionmailer (= 3.1.0.rc4)
@@ -75,17 +75,18 @@ GEM
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2)
- rdoc (3.6.1)
- sprockets (2.0.0.beta.10)
- hike (~> 1.0)
+ rdoc (3.9.4)
+ sprockets (2.0.0)
+ hike (~> 1.2)
rack (~> 1.0)
- tilt (!= 1.3.0, ~> 1.1)
- sqlite3 (1.3.3)
+ tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.4)
thor (0.14.6)
- tilt (1.3.2)
- treetop (1.4.9)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
polyglot (>= 0.3.1)
- tzinfo (0.3.28)
+ tzinfo (0.3.29)
PLATFORMS
ruby
View
26 lib/date_range_scopes.rb
@@ -30,11 +30,14 @@ module DateRangeScopes
time = time.respond_to?(:to_time_in_current_zone) ?
time.to_time_in_current_zone : time
- where(
- "#{full_name} >= ? AND #{full_name} <= ?",
- time.beginning_of_day,
- time.end_of_day
- )
+ starts_at = time.beginning_of_day
+ ends_at = time.end_of_day
+ if key =~ /_on\z/
+ starts_at = starts_at.to_date
+ ends_at = ends_at.to_date
+ end
+
+ where "#{full_name} >= ? AND #{full_name} <= ?", starts_at, ends_at
}
scope "#{key}_today", send("#{key}_on")
@@ -45,11 +48,14 @@ module DateRangeScopes
time = time.respond_to?(:to_time_in_current_zone) ?
time.to_time_in_current_zone : time
- where(
- "#{full_name} >= ? AND #{full_name} <= ?",
- time.send("beginning_of_#{period}"),
- time.send("end_of_#{period}")
- )
+ starts_at = time.send("beginning_of_#{period}")
+ ends_at = time.send("end_of_#{period}")
+ if key =~ /_on\z/
+ starts_at = starts_at.to_date
+ ends_at = ends_at.to_date
+ end
+
+ where "#{full_name} >= ? AND #{full_name} <= ?", starts_at, ends_at
}
scope "#{key}_this_#{period}", send("#{key}_in_#{period}")

0 comments on commit 85583c0

Please sign in to comment.