Commit e4c28d0c17614922e65fc03a91ea445014e771be
1 parent
f514b843
Exists in
master
and in
8 other branches
Fixes for mysql adapter
Showing
2 changed files
with
6 additions
and
1 deletions
Show diff stats
lib/groupdate/magic.rb
@@ -85,6 +85,10 @@ module Groupdate | @@ -85,6 +85,10 @@ module Groupdate | ||
85 | raise "Connection adapter not supported: #{adapter_name}" | 85 | raise "Connection adapter not supported: #{adapter_name}" |
86 | end | 86 | end |
87 | 87 | ||
88 | + if adapter_name == "MySQL" && field == :week | ||
89 | + query[0] = "CAST(#{query[0]} AS DATETIME)" | ||
90 | + end | ||
91 | + | ||
88 | group = relation.group(Groupdate::OrderHack.new(relation.send(:sanitize_sql_array, query), field, time_zone)) | 92 | group = relation.group(Groupdate::OrderHack.new(relation.send(:sanitize_sql_array, query), field, time_zone)) |
89 | if options[:series] == false | 93 | if options[:series] == false |
90 | group | 94 | group |
@@ -126,7 +130,7 @@ module Groupdate | @@ -126,7 +130,7 @@ module Groupdate | ||
126 | lambda { |k| k.to_i } | 130 | lambda { |k| k.to_i } |
127 | else | 131 | else |
128 | utc = ActiveSupport::TimeZone["UTC"] | 132 | utc = ActiveSupport::TimeZone["UTC"] |
129 | - lambda { |k| (k.is_a?(String) ? utc.parse(k) : k.to_time).in_time_zone(time_zone) } | 133 | + lambda { |k| (k.is_a?(String) ? utc.parse(k) : (k.is_a?(BigDecimal) ? Time.at(k) : k.to_time)).in_time_zone(time_zone) } |
130 | end | 134 | end |
131 | 135 | ||
132 | count = | 136 | count = |
test/test_helper.rb
@@ -864,6 +864,7 @@ module TestGroupdate | @@ -864,6 +864,7 @@ module TestGroupdate | ||
864 | 864 | ||
865 | def test_zeros_null_value | 865 | def test_zeros_null_value |
866 | create_user nil | 866 | create_user nil |
867 | + User.update_all created_at: nil, created_on: nil # for MySQL adapter | ||
867 | assert_equal 0, call_method(:hour_of_day, :created_at, range: true)[0] | 868 | assert_equal 0, call_method(:hour_of_day, :created_at, range: true)[0] |
868 | end | 869 | end |
869 | 870 |