lib/groupdate/series.rb in groupdate-1.0.0 vs lib/groupdate/series.rb in groupdate-1.0.1

- old
+ new

@@ -10,16 +10,18 @@ @time_zone = time_zone @time_range = time_range end def build_series(count) + utc = ActiveSupport::TimeZone["UTC"] + cast_method = case @field when "day_of_week", "hour_of_day" lambda{|k| k.to_i } else - lambda{|k| k.is_a?(Time) ? k : Time.parse(k) } + lambda{|k| (k.is_a?(Time) ? k : utc.parse(k)).utc } end count = Hash[count.map do |k, v| [cast_method.call(k), v] end] @@ -51,11 +53,12 @@ when "hour" time.change(:min => 0) when "day" time.beginning_of_day when "week" - time.beginning_of_week(:sunday) + # beginning_of_week does not support :sunday argument in activesupport < 3.2 + (time - time.wday.days).midnight when "month" time.beginning_of_month else # year time.beginning_of_year end @@ -66,10 +69,10 @@ while time_range.cover?(series.last + step) series << series.last + step end - series.map{|s| s.to_time } + series.map{|s| s.to_time.utc } end Hash[series.map do |k| [k, count[k] || 0] end]