lib/groupdate/adapters/mysql_adapter.rb in groupdate-5.2.4 vs lib/groupdate/adapters/mysql_adapter.rb in groupdate-6.0.0
- old
+ new
@@ -18,29 +18,35 @@
when :day_of_year
["DAYOFYEAR(#{day_start_column})", time_zone, day_start]
when :month_of_year
["MONTH(#{day_start_column})", time_zone, day_start]
when :week
- ["CONVERT_TZ(DATE_FORMAT(#{day_start_column} - INTERVAL ((? + DAYOFWEEK(#{day_start_column})) % 7) DAY, '%Y-%m-%d 00:00:00') + INTERVAL ? second, ?, '+00:00')", time_zone, day_start, 12 - week_start, time_zone, day_start, day_start, time_zone]
+ ["CAST(DATE_FORMAT(#{day_start_column} - INTERVAL ((? + DAYOFWEEK(#{day_start_column})) % 7) DAY, '%Y-%m-%d') AS DATE)", time_zone, day_start, 12 - week_start, time_zone, day_start]
when :quarter
- ["CONVERT_TZ(DATE_FORMAT(DATE(CONCAT(YEAR(#{day_start_column}), '-', LPAD(1 + 3 * (QUARTER(#{day_start_column}) - 1), 2, '00'), '-01')), '%Y-%m-%d %H:%i:%S') + INTERVAL ? second, ?, '+00:00')", time_zone, day_start, time_zone, day_start, day_start, time_zone]
+ ["CAST(CONCAT(YEAR(#{day_start_column}), '-', LPAD(1 + 3 * (QUARTER(#{day_start_column}) - 1), 2, '00'), '-01') AS DATE)", time_zone, day_start, time_zone, day_start]
+ when :day, :month, :year
+ format =
+ case period
+ when :day
+ "%Y-%m-%d"
+ when :month
+ "%Y-%m-01"
+ else # year
+ "%Y-01-01"
+ end
+
+ ["CAST(DATE_FORMAT(#{day_start_column}, ?) AS DATE)", time_zone, day_start, format]
when :custom
["FROM_UNIXTIME((UNIX_TIMESTAMP(#{column}) DIV ?) * ?)", n_seconds, n_seconds]
else
format =
case period
when :second
"%Y-%m-%d %H:%i:%S"
when :minute
"%Y-%m-%d %H:%i:00"
- when :hour
+ else # hour
"%Y-%m-%d %H:00:00"
- when :day
- "%Y-%m-%d 00:00:00"
- when :month
- "%Y-%m-01 00:00:00"
- else # year
- "%Y-01-01 00:00:00"
end
["CONVERT_TZ(DATE_FORMAT(#{day_start_column}, ?) + INTERVAL ? second, ?, '+00:00')", time_zone, day_start, format, day_start, time_zone]
end