Module: Dateslices::Postgresql

Defined in:
lib/dateslices/postgresql.rb

Class Method Summary collapse

Class Method Details

.time_filter(column, field) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/dateslices/postgresql.rb', line 4

def self.time_filter(column, field)
  case field
    when :hour_of_day
      "EXTRACT(HOUR from #{column})"
    when :day_of_week
      "EXTRACT(DOW from #{column})"
    when :day_of_month
      "EXTRACT(DAY from #{column})"
    when :month_of_year
      "EXTRACT(MONTH from #{column})"
    when :week # Postgres weeks start on monday
      "(DATE_TRUNC( 'week', #{column} + INTERVAL '1 day' ) - INTERVAL '1 day')"
    else
      "DATE_TRUNC( '#{field.to_s}' , #{column} )"
  end
end