lib/groupdate/scopes.rb in groupdate-2.0.0 vs lib/groupdate/scopes.rb in groupdate-2.0.1

- old
+ new

@@ -11,19 +11,20 @@ args = args.dup options = args[-1].is_a?(Hash) ? args.pop : {} column = connection.quote_table_name(args[0]) time_zone = args[1] || options[:time_zone] || Groupdate.time_zone || Time.zone || "Etc/UTC" if time_zone.is_a?(ActiveSupport::TimeZone) or time_zone = ActiveSupport::TimeZone[time_zone] + time_zone_object = time_zone time_zone = time_zone.tzinfo.name else raise "Unrecognized time zone" end # for week week_start = [:mon, :tue, :wed, :thu, :fri, :sat, :sun].index((options[:week_start] || options[:start] || Groupdate.week_start).to_sym) if field == "week" and !week_start - raise "Unrecognized :start option" + raise "Unrecognized :week_start option" end # for day day_start = (options[:day_start] || Groupdate.day_start).to_i @@ -51,11 +52,11 @@ "%Y-%m-%d 00:00:00" when "month" "%Y-%m-01 00:00:00" else # year "%Y-01-01 00:00:00" - end + end ["DATE_ADD(CONVERT_TZ(DATE_FORMAT(CONVERT_TZ(DATE_SUB(#{column}, INTERVAL #{day_start} HOUR), '+00:00', ?), '#{format}'), ?, '+00:00'), INTERVAL #{day_start} HOUR)", time_zone, time_zone] end when "PostgreSQL", "PostGIS" case field @@ -73,10 +74,10 @@ end group = group(Groupdate::OrderHack.new(sanitize_sql_array(query), field, time_zone)) range = args[2] || options[:range] || true unless options[:series] == false - Series.new(group, field, column, time_zone, range, week_start, day_start) + Series.new(group, field, column, time_zone_object, range, week_start, day_start) else group end end end