4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/dateslices/sqlite.rb', line 4
def self.time_filter(column, field)
case field
when :second
"strftime( \"%Y-%m-%d %H:%M:%S UTC\", #{column} )"
when :minute
"strftime( \"%Y-%m-%d %H:%M:00 UTC\", #{column} )"
when :hour
"strftime( \"%Y-%m-%d %H:00:00 UTC\", #{column} )"
when :day
"strftime( \"%Y-%m-%d 00:00:00 UTC\", #{column} )"
when :week
"strftime('%Y-%m-%d 00:00:00 UTC', #{column}, '-6 days', 'weekday 0')"
when :month
"strftime( \"%Y-%m-01 00:00:00 UTC\", #{column} )"
when :year
"strftime( \"%Y-01-01 00:00:00 UTC\", #{column} )"
when :hour_of_day
"strftime( \"%H\", #{column} )"
when :day_of_week
"strftime( \"%w\", #{column} )"
when :day_of_month
"strftime( \"%d\", #{column} )"
when :month_of_year
"strftime( \"%m\", #{column} )"
else
throw "Unknown time filter #{field}"
end
end
|