Skip to content
This repository has been archived by the owner on Dec 1, 2017. It is now read-only.

Commit

Permalink
add postgres corrections to duration methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski committed Dec 6, 2010
1 parent 37504b3 commit 21a6cb7
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/pacecar/duration.rb
Expand Up @@ -23,6 +23,16 @@ def define_duration_scopes
scope :with_duration_under, lambda { |duration, start, stop|
{ :conditions => ["abs(datediff(#{quoted_table_name}.#{connection.quote_column_name start}, #{quoted_table_name}.#{connection.quote_column_name stop})) < ?", duration] }
}
when 'PostgreSQL'
scope :with_duration_of, lambda { |duration, start, stop|
{ :conditions => ["age(#{quoted_table_name}.#{connection.quote_column_name stop}, #{quoted_table_name}.#{connection.quote_column_name start}) = '? days'", duration] }
}
scope :with_duration_over, lambda { |duration, start, stop|
{ :conditions => ["age(#{quoted_table_name}.#{connection.quote_column_name stop}, #{quoted_table_name}.#{connection.quote_column_name start}) > interval '? days'", duration] }
}
scope :with_duration_under, lambda { |duration, start, stop|
{ :conditions => ["age(#{quoted_table_name}.#{connection.quote_column_name stop}, #{quoted_table_name}.#{connection.quote_column_name start}) < interval '? days'", duration] }
}
when 'SQLite'
scope :with_duration_of, lambda { |duration, start, stop|
{ :conditions => ["abs(julianday(#{quoted_table_name}.#{connection.quote_column_name start}) - julianday(#{quoted_table_name}.#{connection.quote_column_name stop})) = ?", duration] }
Expand Down

0 comments on commit 21a6cb7

Please sign in to comment.